forked from ubc-web-services/galactus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
galactus.theme
executable file
·383 lines (347 loc) · 14 KB
/
galactus.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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<?php
/**
* @file
* Functions to support theming in the galactus theme.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_page_attachments_alter().
*/
function galactus_page_attachments_alter(array &$page) {
$use_minimal_clf = theme_get_setting('clf_override');
$clf_theme_color = theme_get_setting('clf_theme_colour');
$clf_layout = theme_get_setting('clf_layout');
if ($clf_layout == 'full' || $clf_layout == 'fluid') {
$clf_layout_id = 'fw';
}
else {
$clf_layout_id = 'sw';
}
// Switch between minimal and full CLF libraries.
if ($use_minimal_clf) {
$page['#attached']['library'][] = 'galactus/clf-' . $clf_layout_id . '-' . $clf_theme_color;
}
else {
// Use full CLF library.
$page['#attached']['library'][] = 'galactus/clf-cdn-fw-' . $clf_theme_color;
}
}
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*
* Adds body classes if certain regions have content.
*/
function galactus_preprocess_html(&$variables) {
// Add in custom theme variables so they are available in html.twig.
$variables['color_option'] = theme_get_setting('clf_theme_colour');
$variables['layout_option2'] = theme_get_setting('clf_layout');
$variables['local_clf'] = theme_get_setting('clf_override');
$variables['unuglify'] = theme_get_setting('unuglify') ? TRUE : FALSE;
// Add Apple Touch Icons.
$clf_apple_touch_144 = [
'#tag' => 'link',
'#attributes' => [
'href' => 'https://cdn.ubc.ca/clf/7.0.4/img/apple-touch-icon-144-precomposed.png',
'rel' => 'apple-touch-icon-precomposed',
'sizes' => '144x144',
],
];
$clf_apple_touch_114 = [
'#tag' => 'link',
'#attributes' => [
'href' => 'https://cdn.ubc.ca/clf/7.0.4/img/apple-touch-icon-114-precomposed.png',
'rel' => 'apple-touch-icon-precomposed',
'sizes' => '114x114',
],
];
$clf_apple_touch_72 = [
'#tag' => 'link',
'#attributes' => [
'href' => 'https://cdn.ubc.ca/clf/7.0.4/img/apple-touch-icon-72-precomposed.png',
'rel' => 'apple-touch-icon-precomposed',
'sizes' => '72x72',
],
];
$clf_apple_touch = [
'#tag' => 'link',
'#attributes' => [
'href' => 'https://cdn.ubc.ca/clf/7.0.4/img/apple-touch-icon-57-precomposed.png',
'rel' => 'apple-touch-icon-precomposed',
],
];
$variables['page']['#attached']['html_head'][] = [$clf_apple_touch_144, 'clf-apple-touch-144'];
$variables['page']['#attached']['html_head'][] = [$clf_apple_touch_114, 'clf-apple-touch-114'];
$variables['page']['#attached']['html_head'][] = [$clf_apple_touch_72, 'clf-apple-touch-72'];
$variables['page']['#attached']['html_head'][] = [$clf_apple_touch, 'clf-apple-touch'];
/* Add a NOFOLLOW tag if the site is not meant for production */
if (theme_get_setting('clf_noindex') == TRUE) {
$nofollow = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'name' => 'robots',
'content' => 'noindex, nofollow',
],
];
$variables['page']['#attached']['html_head'][] = [$nofollow, 'nofollow'];
}
$prefetch = [
'#type' => 'html_tag',
'#tag' => 'link',
'#attributes' => [
'rel' => 'dns-prefetch',
'href' => 'https://cdn.ubc.ca',
],
];
$variables['page']['#attached']['html_head'][] = [$prefetch, 'prefetch'];
/* Add Google nad Bing Verification Tags */
$googleVerificationCode = theme_get_setting('clf_google_verify');
if (!empty(theme_get_setting('clf_google_verify'))) {
$googleverify = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'name' => 'google-site-verification',
'content' => $googleVerificationCode,
],
];
$variables['page']['#attached']['html_head'][] = [$googleverify, 'googleverify'];
}
$bingVerificationCode = theme_get_setting('clf_bing_verify');
if (!empty(theme_get_setting('clf_bing_verify'))) {
$bingverify = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'name' => 'msvalidate.01',
'content' => $bingVerificationCode,
],
];
$variables['page']['#attached']['html_head'][] = [$bingverify, 'bingverify'];
}
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'layout-two-sidebars';
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['attributes']['class'][] = 'layout-one-sidebar';
$variables['attributes']['class'][] = 'layout-sidebar-first';
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'layout-one-sidebar';
$variables['attributes']['class'][] = 'layout-sidebar-second';
}
else {
$variables['attributes']['class'][] = 'layout-no-sidebars';
}
if (!empty($variables['page']['featured'])) {
$variables['attributes']['class'][] = 'featured';
}
// Add inline banner colour.
$unit_color_option = theme_get_setting('clf_theme_unit_colour');
if (!empty($unit_color_option)) {
$variables['page']['#attached']['html_head'][] = [
[
'#tag' => 'style',
'#value' => '#ubc7-unit { background-color: #' . $unit_color_option . ' !important; }',
],
'unit-colour-css',
];
}
// Add sticky class and library.
if (theme_get_setting('clf_navigation_sticky') == TRUE) {
$variables['attributes']['class'][] = 'clf-navigation-sticky';
$variables['#attached']['library'][] = 'galactus/clf-sticky-navigation';
}
// Add secondary navigation class and library.
if (theme_get_setting('clf_secondarynavoption') == TRUE) {
$variables['attributes']['class'][] = 'clf-navigation-secondary';
$variables['#attached']['library'][] = 'galactus/clf-secondary-navigation';
}
// Add navigation class and library.
if (theme_get_setting('clf_navigation_placement') == 'default') {
$variables['navigation_placement'] = FALSE;
$variables['attributes']['class'][] = 'clf-navigation-default';
}
else {
$variables['attributes']['class'][] = 'clf-navigation-slidein';
$variables['#attached']['library'][] = 'galactus/clf-slidein-navigation';
}
// Add Whitney library if set.
if (theme_get_setting('clf_use_whitney') == 'dev') {
$variables['#attached']['library'][] = 'galactus/clf-whitney-dev';
}
if (theme_get_setting('clf_use_whitney') == 'prod') {
$variables['#attached']['library'][] = 'galactus/clf-whitney-prod';
}
// Add Fontawesome library if set.
if (theme_get_setting('clf_fontawesome') == TRUE) {
$variables['#attached']['library'][] = 'galactus/clf-fontawesome';
}
}
/**
* Implements hook_preprocess_HOOK() for page templates.
*/
function galactus_preprocess_page(&$variables) {
// Since the title and the shortcut link are both block level elements,
// positioning them next to each other is much simpler with a wrapper div.
if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
// Add a wrapper div using the title_prefix and title_suffix render
// elements.
$variables['title_prefix']['shortcut_wrapper'] = [
'#markup' => '<div class="shortcut-wrapper clearfix">',
'#weight' => 100,
];
$variables['title_suffix']['shortcut_wrapper'] = [
'#markup' => '</div>',
'#weight' => -99,
];
// Make sure the shortcut link is the first item in title_suffix.
$variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
}
// Add in our custom theme variables so we can use them in page.twig
// general options.
$variables['layout_option'] = theme_get_setting('clf_layout');
$variables['mobilenav_option'] = theme_get_setting('clf_navoption') ? FALSE : TRUE;
$variables['campus_option'] = theme_get_setting('clf_unit_campus');
$variables['faculty_option'] = theme_get_setting('clf_faculty') ? FALSE : TRUE;
$variables['faculty_name'] = theme_get_setting('clf_faculty_name');
$variables['unit_name'] = theme_get_setting('clf_unitname');
// Search options.
$variables['searchlabel_option'] = theme_get_setting('clf_searchlabel');
$variables['searchdomain_option'] = theme_get_setting('clf_searchdomain');
// Content layout classes.
$variables['content_row_class_option'] = theme_get_setting('clf_content_row_class');
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['content_class_option'] = theme_get_setting('clf_two_sidebar_class');
$variables['sidebar_first_class_option'] = theme_get_setting('clf_two_sidebar_class_sidebar1');
$variables['sidebar_second_class_option'] = theme_get_setting('clf_two_sidebar_class_sidebar2');
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['content_class_option'] = theme_get_setting('clf_one_sidebar_class');
$variables['sidebar_first_class_option'] = theme_get_setting('clf_one_sidebar_class_sidebar');
$variables['sidebar_second_class_option'] = '';
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['content_class_option'] = theme_get_setting('clf_one_sidebar_class');
$variables['sidebar_first_class_option'] = '';
$variables['sidebar_second_class_option'] = theme_get_setting('clf_one_sidebar_class_sidebar');
}
else {
$variables['content_class_option'] = theme_get_setting('clf_no_sidebar_class');
$variables['sidebar_first_class_option'] = '';
$variables['sidebar_second_class_option'] = '';
}
// Navigation options.
if (theme_get_setting('clf_navigation_placement') == 'default') {
$variables['navigation_placement_default'] = TRUE;
$variables['navigation_placement'] = FALSE;
}
else {
$variables['navigation_placement_drawer'] = TRUE;
$variables['navigation_placement'] = theme_get_setting('clf_navigation_placement');
}
// Footer options.
$variables['address_option'] = theme_get_setting('clf_streetaddr');
$variables['locality_option'] = theme_get_setting('clf_locality');
$variables['region_option'] = theme_get_setting('clf_region');
$variables['country_option'] = theme_get_setting('clf_country');
$variables['postal_option'] = theme_get_setting('clf_postal');
$variables['phone_option'] = theme_get_setting('clf_telephone');
$variables['fax_option'] = theme_get_setting('clf_fax');
$variables['email_option'] = theme_get_setting('clf_email');
$variables['website_option'] = theme_get_setting('clf_website');
// Social media options.
$variables['facebook_option'] = theme_get_setting('clf_social_facebook');
$variables['twitter_option'] = theme_get_setting('clf_social_twitter');
$variables['linkedin_option'] = theme_get_setting('clf_social_linkedin');
$variables['instagram_option'] = theme_get_setting('clf_social_instagram');
$variables['youtube_option'] = theme_get_setting('clf_social_youtube');
}
/**
* Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
*/
function galactus_preprocess_maintenance_page(&$variables) {
// By default, site_name is set to Drupal if no db connection is available
// or during site installation. Setting site_name to an empty string makes
// the site and update pages look cleaner.
// @see template_preprocess_maintenance_page
if (!$variables['db_is_active']) {
$variables['site_name'] = '';
}
// Galactus has custom styling for the maintenance page.
$variables['#attached']['library'][] = 'galactus/maintenance_page';
}
/**
* Implements hook_preprocess_HOOK() for node.html.twig.
*/
function galactus_preprocess_node(&$variables) {
// Remove the "Add new comment" link on teasers or when the comment form is
// displayed on the page.
if ($variables['teaser'] || !empty($variables['content']['comments']['comment_form'])) {
unset($variables['content']['links']['comment']['#links']['comment-add']);
}
// Add node--node_type--view_mode.html.twig suggestions.
$variables['theme_hook_suggestions'][] = 'node__' . $variables['elements']['#node']->bundle() . '__' . $variables['view_mode'];
// Add node--view_mode.html.twig suggestions.
$variables['theme_hook_suggestions'][] = 'node__' . $variables['view_mode'];
}
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function galactus_preprocess_block(&$variables) {
// Add a clearfix class to system branding blocks.
if ($variables['plugin_id'] == 'system_branding_block') {
$variables['attributes']['class'][] = 'clearfix';
}
}
/**
* Implements hook_preprocess_HOOK() for menu.html.twig.
*/
function galactus_preprocess_menu(&$variables) {
$variables['attributes']['class'][] = 'clearfix';
}
/**
* Implements hook_preprocess_HOOK() for field.html.twig.
*
* @see template_preprocess_field()
*/
function galactus_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'taxonomy_term_reference') {
$variables['title_attributes']['class'][] = 'field-label';
if ($variables['element']['#label_display'] == 'inline') {
$variables['title_attributes']['class'][] = 'inline';
}
}
}
/**
* Implements hook_form_alter() for forms.
*/
function galactus_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if ($form_id == 'search_block_form') {
$form['keys']['#theme_wrappers'] = NULL;
$form['keys']['#prefix'] = '<div class="form-inline input-append">';
$form['keys']['#attributes']['placeholder'] = t('Search...');
$form['actions']['#theme_wrappers'] = NULL;
$form['actions']['submit']['#attributes']['class'][] = 'btn btn-primary';
$form['actions']['#suffix'] = '</div>';
}
if ($form_id == 'user_login_form') {
$form['actions']['#theme_wrappers'] = NULL;
$form['actions']['submit']['#attributes']['class'][] = 'btn btn-primary btn-block';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for page.html.twig.
*/
function galactus_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// Get current node.
$node = \Drupal::request()->attributes->get('node');
if ($node) {
// Add the Node Type as a template suggestion.
if ($node->getType()) {
$suggestions[] = 'page__node_type__' . $node->getType();
}
}
}