-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwxt_bootstrap.theme
283 lines (245 loc) · 9.21 KB
/
wxt_bootstrap.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<?php
/**
* @file
* The primary PHP file for the Drupal WxT Bootstrap base theme.
*
* This file should only contain light helper functions and point to stubs in
* other files containing more complex functions.
*
* The stubs should point to files within the `./includes` directory named after
* the function itself minus the theme prefix. If the stub contains a group of
* functions, then please organize them so they are related in some way and name
* the file appropriately to at least hint at what it contains.
*
* All [pre]process functions, theme functions and template files lives inside
* the `./templates` directory. This is a highly automated and complex system
* designed to only load the necessary files when a given theme hook is invoked.
*
* Visit this project's official documentation site https://drupal-bootstrap.org
* or the markdown files inside the `./docs` directory.
*
* @see bootstrap_theme()
* @see \Drupal\bootstrap\Registry
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Entity\File;
use Drupal\node\NodeInterface;
/**
* Implements hook_form_alter().
*/
function wxt_bootstrap_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (strpos($form_id, 'wxt_search') >= 0 && isset($form['form_build_id'])) {
if ($form['form_build_id']['#type'] == 'hidden') {
// WCAG forbids hidden input elements with an autocomplete on/off.
unset($form['form_build_id']['#attributes']['autocomplete']);
}
}
}
/**
* Implements hook_preprocess_page().
*/
function wxt_bootstrap_preprocess_page(&$variables) {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
if ($language == 'en') {
$variables['main_menu_label'] = '<span class="wb-inv">Main </span>Menu <span class="expicon glyphicon glyphicon-chevron-down"></span>';
$variables['lang_iso_639_2'] = 'eng';
}
elseif ($language == 'fr') {
$variables['main_menu_label'] = 'Menu<span class="wb-inv"> principal</span> <span class="expicon glyphicon glyphicon-chevron-down"></span>';
$variables['lang_iso_639_2'] = 'fra';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_page_alter(array &$suggestions, array $variables) {
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('wxt_ext_book')) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof NodeInterface) {
if (!empty($node->book) && $node->book['bid'] != 0) {
/** @var \Drupal\wxt_library\LibraryService $wxt */
$wxt = \Drupal::service('wxt_library.service_wxt');
$wxt_active = $wxt->getLibraryName();
if ($node->book['bid'] == $node->id()) {
// Theme book index page.
$suggestions[] = $variables['theme_hook_original'] . '__book_index';
$suggestions[] = $variables['theme_hook_original'] . '__' . $wxt_active . '__book_index';
}
else {
// Theme book child page.
$suggestions[] = $variables['theme_hook_original'] . '__book_page';
$suggestions[] = $variables['theme_hook_original'] . '__' . $wxt_active . '__book_page';
}
}
}
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_book_navigation_alter(array &$suggestions, array $variables) {
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('wxt_ext_book')) {
$suggestions[] = $variables['theme_hook_original'] . '__gcweb';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_book_tree_alter(array &$suggestions, array $variables) {
$moduleHandler = \Drupal::service('module_handler');
if ($moduleHandler->moduleExists('wxt_ext_book')) {
$suggestions[] = 'book_tree__gcweb';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_views_view_alter(&$suggestions, $variables) {
$view = $variables['view'];
$suggestions[] = "views_view__" . $view->id();
$suggestions[] = "views_view__" . $view->id() . "__" . $view->current_display;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_views_view_unformatted_alter(&$suggestions, $variables) {
$view = $variables['view'];
$suggestions[] = "views_view_unformatted__" . $view->id();
$suggestions[] = "views_view_unformatted__" . $view->id() . "__" . $view->current_display;
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function wxt_bootstrap_theme_suggestions_views_view_list_alter(&$suggestions, $variables) {
$view = $variables['view'];
$suggestions[] = "views_view_list__" . $view->id();
$suggestions[] = "views_view_list__" . $view->id() . "__" . $view->current_display;
}
/**
* Implements hook_preprocess_block().
*/
function wxt_bootstrap_preprocess_block(&$variables) {
$plugin_id = $variables['elements']['#plugin_id'];
if ($plugin_id == 'system_branding_block') {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
if ($language == 'en') {
$variables['language_opposite'] = 'fr';
$variables['label_opposite'] = 'Gouvernement du Canada';
}
elseif ($language == 'fr') {
$variables['language_opposite'] = 'en';
$variables['label_opposite'] = 'Government of Canada';
}
}
if (strpos($plugin_id, 'facet_block') !== FALSE) {
$theme_name = \Drupal::theme()->getActiveTheme()->getName();
$collapsible_facets = theme_get_setting('wxt_facets_collapsible', $theme_name);
$facet_panel_type = theme_get_setting('wxt_facets_panel_type', $theme_name);
$variables['collapsible_facets'] = $collapsible_facets;
$variables['facet_panel_type'] = $facet_panel_type;
}
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('wxt_ext_blocks')) {
$variables['label_display'] = TRUE;
}
}
/**
* Implements hook_preprocess_input__button().
*/
function wxt_bootstrap_preprocess_input__button(&$vars) {
if (isset($vars['attributes'])) {
$attrObj = $vars['attributes'];
if ($attrObj->offsetExists('id') && $attrObj->offsetGet('id')->__toString() == 'wb-srch-sub') {
$attrObj->setAttribute('title', t('Search'));
}
}
}
/**
* Implements hook_preprocess_image().
*/
function wxt_bootstrap_preprocess_image(&$vars) {
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name == 'page_manager.page_view_blog_blog-panels_variant-0') {
if ($vars['style_name'] == 'blog_spotlight') {
unset($vars['attributes']['width']);
unset($vars['attributes']['height']);
$vars['attributes']['class'] = 'mrgn-bttm-md thumbnail';
}
}
}
/**
* Implements hook_preprocess_input().
*/
function wxt_bootstrap_preprocess_input(&$variables) {
if (!empty($variables['attributes']['id'])) {
$id = $variables['attributes']['id']->value();
}
if (!empty($id) && $id == 'wb-srch-sub') {
$variables['search_submit'] = 'true';
}
else {
$variables['search_submit'] = 'false';
}
}
/**
* Implements hook_preprocess_filter_caption().
*/
function wxt_bootstrap_preprocess_filter_caption(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if (!$node instanceof NodeInterface) {
// Show caption if not on a node page to ensure it displays in CKEditor.
$variables['show_caption'] = TRUE;
}
}
/**
* Implements hook_preprocess_field().
*/
function wxt_bootstrap_preprocess_field(&$variables) {
if ($variables['element']['#bundle'] == 'remote_video') {
// Get title and URL of remote video.
$youtube_domains = [
'youtube.com',
'youtu.be',
];
$video_url = $variables['element']['#items'][0]->getValue()['value'];
foreach ($youtube_domains as $domain) {
if (strpos($video_url, $domain) !== FALSE) {
$variables['video_title'] = $variables['element'][0]['#attributes']['title'];
$variables['video_url'] = $video_url;
break;
}
}
}
if ($variables['element']['#bundle'] == 'video' && $variables['element']['#field_name'] == 'field_media_video_file') {
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
$media = $variables['element']['#object'];
if ($lang == 'fr' && $media->hasTranslation($lang)) {
$media = $media->getTranslation($lang);
}
$fid = $media->get('field_media_video_file')->getValue()[0]['target_id'];
$file = File::load($fid);
$video_uri = $file->getFileUri();
$variables['video_uri'] = \Drupal::service('file_url_generator')->generateString($video_uri);
$variables['video_title'] = $media->getName();
}
}
/**
* Implements hook_preprocess_media().
*/
function wxt_bootstrap_preprocess_media(&$variables) {
$variables['attributes']['class'][] = 'wxt-media-' . str_replace('_', '-', $variables['view_mode']);
}
/**
* Implements hook_preprocess_page_title().
*/
function wxt_bootstrap_preprocess_page_title(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof NodeInterface && $node->hasField('field_lead_title')) {
$variables['gc_thickline'] = TRUE;
if (!empty($node->get('field_lead_title')->getValue()[0]['value'])) {
$variables['lead_title'] = $node->get('field_lead_title')->getValue()[0]['value'];
}
}
}