-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvartheme_bs5.theme
125 lines (103 loc) · 4.1 KB
/
vartheme_bs5.theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* @file
* Theme functions to support Vartheme BS5 theme.
*/
use Drupal\Core\Language\LanguageInterface;
/**
* Implements hook_preprocess_page().
*/
function vartheme_bs5_preprocess_page(&$variables) {
// Add the print logo.
$variables['logo_print'] = \Drupal::request()->getBaseUrl() . '/' . \Drupal::service('extension.list.theme')->getPath('vartheme_bs5') . '/logo-print.png';
// Add the white logo.
$variables['logo_white'] = \Drupal::request()->getBaseUrl() . '/' . \Drupal::service('extension.list.theme')->getPath('vartheme_bs5') . '/logo-white.svg';
// Add the site name and slogan.
$variables['site_name'] = \Drupal::config('system.site')->get('name');
$variables['site_slogan'] = \Drupal::config('system.site')->get('slogan');
$vartheme_bs5_contained_regions = [
'container_top_bar',
// 'container_navbar_branding',
// 'container_navigation',
// 'container_highlighted',
'container_content_above',
// 'container_primary_sidebar',
'container_content',
// 'container_secondary_sidebar',
'container_content_below',
'container_footer_top',
'container_footer_bottom',
];
foreach ($vartheme_bs5_contained_regions as $contained_region) {
$theme_settings_for_contained_region = theme_get_setting($contained_region);
if (isset($theme_settings_for_contained_region)
&& $theme_settings_for_contained_region !== '') {
$variables[$contained_region] = $theme_settings_for_contained_region;
}
}
}
/**
* Implements hook_preprocess_page_title().
*/
function vartheme_bs5_preprocess_page_title(&$variables) {
// Hide page title for the front page and let screen readers only see it.
if (\Drupal::service('path.matcher')->isFrontPage()) {
$variables['title_attributes']['class'][] = 'visually-hidden';
}
}
/**
* Implements hook_preprocess_html().
*/
function vartheme_bs5_preprocess_html(&$variables) {
// The path for Vartheme BS5 theme in variables.
$variables['vartheme_bs5_path'] = \Drupal::request()->getBaseUrl() . '/' . \Drupal::service('extension.list.theme')->getPath('vartheme_bs5');
}
/**
* Implements hook_form_alter().
*/
function vartheme_bs5_form_alter(&$form, $form_state, $form_id) {
// Have a default style for moderation entity form.
if ($form_id == 'content_moderation_entity_moderation_form') {
$form['#attributes']['class'][] = 'card card-body bg-light mb-3';
}
// Have a default style for the moderation status in the layout editing node pages.
if ((preg_match('/^node_.*._layout_builder_form$/', $form_id)
&& isset($form['moderation_state']))) {
$form['moderation_state']['#attributes']['class'][] = 'card card-body bg-light mb-3';
$form['#attached']['library'][] = 'vartheme_bs5/content_moderation';
}
}
/**
* Implements hook_preprocess_login_with().
*/
function vartheme_bs5_preprocess_login_with(&$variables) {
if (\Drupal::moduleHandler()->moduleExists('social_auth')) {
foreach ($variables['social_networks'] as $social_network_index => $social_network) {
if (isset($social_network['img_path'])) {
$theme_path = \Drupal::service('extension.list.theme')->getPath('vartheme_bs5');
$replaced_path_for_icons = str_replace('modules/contrib', 'social_auth', $social_network['img_path']);
$social_network_img_path_in_vartheme = $theme_path . '/images/' . $replaced_path_for_icons;
if (file_exists(DRUPAL_ROOT . '/' . $social_network_img_path_in_vartheme)) {
$variables['social_networks'][$social_network_index]['img_path'] = $social_network_img_path_in_vartheme;
}
}
}
}
}
/**
* Implements hook_preprocess_region().
*/
function vartheme_bs5_preprocess_region(&$variables) {
$isFront = \Drupal::service('path.matcher')->isFrontPage();
if ($isFront && $variables["region"] === "header") {
$variables["is_front"] = $isFront;
}
}
/**
* Implements hook_preprocess().
*/
function vartheme_bs5_preprocess(&$variables, $hook, $info) {
$language = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT);
$language_direction = $language->getDirection();
$variables['lang_dir'] = $language_direction;
}