-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathillinois_framework_theme.theme
More file actions
762 lines (686 loc) · 31.8 KB
/
illinois_framework_theme.theme
File metadata and controls
762 lines (686 loc) · 31.8 KB
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
<?php
declare(strict_types=1);
use Drupal\Core\Url;
use \Drupal\Core\Form\FormStateInterface;
use Drupal\node\NodeInterface;
use Drupal\block\Entity\Block;
use Drupal\Core\Site\Settings;
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\paragraphs\ParagraphInterface;
/**
* Implements hook_preprocess().
*/
function illinois_framework_theme_preprocess(array &$variables) {
// Set the 'node' attribute in the request during previews so blocks and
// menu trees can correctly identify the node context. This must happen
// early in the rendering process.
$route_match = \Drupal::routeMatch();
if ($route_match->getRouteName() === 'entity.node.preview') {
$node = $route_match->getParameter('node_preview');
if ($node instanceof NodeInterface) {
\Drupal::request()->attributes->set('node', $node);
}
}
// Get the current user service.
$current_user = \Drupal::currentUser();
// Check if the user is authenticated to dynamically set the login/logout link.
if ($current_user->isAuthenticated()) {
// --- USER IS LOGGED IN ---
// Set the link text to "Logout".
$variables['login_logout_text'] = t('Logout');
$variables['login_logout_url'] = Url::fromRoute('user.logout');
}
else {
// --- USER IS LOGGED OUT ---
// Set the link text to "Login".
$variables['login_logout_text'] = t('Login');
// Get the current page path to use as the destination parameter for the redirect.
$destination = \Drupal::service('redirect.destination')->getAsArray();
// Get the theme setting for direct Shibboleth login.
$shibboleth_direct_login = theme_get_setting('if_shibboleth_login_direct');
// Default SAML status to inactive.
$saml_is_active = FALSE;
// First, check if the simplesamlphp_auth module exists before trying to access its configuration.
if (\Drupal::moduleHandler()->moduleExists('simplesamlphp_auth')) {
// If it exists, get the configuration and check if it's active.
$saml_config = \Drupal::config('simplesamlphp_auth.settings');
$saml_is_active = $saml_config->get('activate');
}
// Check if the theme setting is enabled and the SAML module is active for authentication.
if ($shibboleth_direct_login && $saml_is_active) {
// The module is enabled and active, so point to the Shibboleth login with the destination.
$login_url = Url::fromRoute('simplesamlphp_auth.saml_login', [], ['query' => $destination]);
}
else {
// The module is not enabled, so use the standard Drupal login with the destination.
$login_url = Url::fromRoute('user.login', [], ['query' => $destination]);
}
$variables['login_logout_url'] = $login_url;
}
// TODO: Condense these into a single array like ['path_vars']['var'].
$current_path = \Drupal::service('path.current')->getPath();
$canoncial_url = Url::fromRoute('<current>', [], ['absolute' => 'true'])->toString();
$base_path = \Drupal::request()->getHost();
$base_path_http = \Drupal::request()->getSchemeAndHttpHost();
$variables['site_name_source'] = get_clean_system_site_name();
$theme_path = \Drupal::theme()->getActiveTheme()->getPath();
$variables['current_uri'] = \Drupal::request()->getRequestUri();
$variables['canoncial_url'] = $canoncial_url;
$variables['current_path'] = $current_path;
$variables['base_path'] = $base_path;
$variables['base_path_http'] = $base_path_http;
$variables['base_path_success'] = (array_key_exists('HTTPS', $_SERVER) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
$variables['theme_path'] = $theme_path;
$variables['files_path'] = $base_path_http . '/sites/' . $base_path . '/files/';
$variables['#attached']['drupalSettings']['google_cse']['google_api'] = Settings::get('google_api', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
// Theme variables.
$variables['if_secondary_site_title'] = theme_get_setting('if_secondary_site_title');
$variables['if_secondary_site_link'] = theme_get_setting('if_secondary_site_link');
$variables['if_header_links'][0][0] = theme_get_setting('if_header_text_1');
$variables['if_header_links'][0][1] = theme_get_setting('if_header_link_1');
$variables['if_header_links'][1][0] = theme_get_setting('if_header_text_2');
$variables['if_header_links'][1][1] = theme_get_setting('if_header_link_2');
$variables['if_header_links'][2][0] = theme_get_setting('if_header_text_3');
$variables['if_header_links'][2][1] = theme_get_setting('if_header_link_3');
$variables['if_footer_google_translate'] = theme_get_setting('if_footer_google_translate');
$variables['if_footer']['if_footer_address']['if_footer_address_unit'] = theme_get_setting('if_footer_address_unit');
$variables['if_footer']['if_footer_address']['if_footer_address_street_one'] = theme_get_setting('if_footer_address_street_one');
$variables['if_footer']['if_footer_address']['if_footer_address_street_two'] = theme_get_setting('if_footer_address_street_two');
$variables['if_footer']['if_footer_address']['if_footer_address_city'] = theme_get_setting('if_footer_address_city');
$variables['if_footer']['if_footer_address']['if_footer_address_state'] = theme_get_setting('if_footer_address_state');
$variables['if_footer']['if_footer_address']['if_footer_address_zip'] = theme_get_setting('if_footer_address_zip');
$variables['if_footer']['if_footer_address']['if_footer_address_tel'] = theme_get_setting('if_footer_address_tel');
$variables['if_footer']['if_footer_address']['if_footer_address_email'] = theme_get_setting('if_footer_address_email');
// Set the social media links into a variable so we can use array_filter to exclude empty items
$if_footer_social = [
// Use the lowercase name of the social media supported by the framework.
'instagram' => theme_get_setting('if_footer_social_instagram'),
'facebook' => theme_get_setting('if_footer_social_facebook'),
// Add an override for the setting to adjust for renaming twitter to x.
'x' => theme_get_setting('if_footer_social_twitter'),
'youtube' => theme_get_setting('if_footer_social_youtube'),
'linkedin' => theme_get_setting('if_footer_social_linkedin'),
'bluesky' => theme_get_setting('if_footer_social_bluesky'),
'calendar' => theme_get_setting('if_footer_social_calendar'),
'tiktok' => theme_get_setting('if_footer_social_tiktok'),
'pinterest' => theme_get_setting('if_footer_social_pinterest'),
'snapchat' => theme_get_setting('if_footer_social_snapchat'),
'weibo' => theme_get_setting('if_footer_social_weibo'),
'whatsapp' => theme_get_setting('if_footer_social_whatsapp'),
'threads' => theme_get_setting('if_footer_social_threads'),
];
// Remove empty elements and set them to the right variable
$variables['if_footer']['if_footer_social'] = array_filter($if_footer_social);
$variables['if_footer_colleges'][0][0] = theme_get_setting('if_footer_college_text_1');
$variables['if_footer_colleges'][0][1] = theme_get_setting('if_footer_college_link_1');
$variables['if_footer_colleges'][1][0] = theme_get_setting('if_footer_college_text_2');
$variables['if_footer_colleges'][1][1] = theme_get_setting('if_footer_college_link_2');
$variables['if_footer_colleges'][2][0] = theme_get_setting('if_footer_college_text_3');
$variables['if_footer_colleges'][2][1] = theme_get_setting('if_footer_college_link_3');
$variables['if_footer_colleges'][3][0] = theme_get_setting('if_footer_college_text_4');
$variables['if_footer_colleges'][3][1] = theme_get_setting('if_footer_college_link_4');
$variables['if_footer_colleges'][4][0] = theme_get_setting('if_footer_college_text_5');
$variables['if_footer_colleges'][4][1] = theme_get_setting('if_footer_college_link_5');
$variables['if_footer_colleges']['if_footer_colleges_one'] = theme_get_setting('if_footer_colleges_one');
$variables['if_footer']['if_footer_menu_block_checkbox'] = theme_get_setting('if_footer_menu_block_checkbox');
$variables['if_subfooter'][0][0] = theme_get_setting('if_subfooter_text_1');
$variables['if_subfooter'][0][1] = theme_get_setting('if_subfooter_link_1');
$variables['if_subfooter'][1][0] = theme_get_setting('if_subfooter_text_2');
$variables['if_subfooter'][1][1] = theme_get_setting('if_subfooter_link_2');
$variables['if_subfooter'][2][0] = theme_get_setting('if_subfooter_text_3');
$variables['if_subfooter'][2][1] = theme_get_setting('if_subfooter_link_3');
$variables['if_subfooter'][3][0] = theme_get_setting('if_subfooter_text_4');
$variables['if_subfooter'][3][1] = theme_get_setting('if_subfooter_link_4');
$variables['if_subfooter'][4][0] = theme_get_setting('if_subfooter_text_5');
$variables['if_subfooter'][4][1] = theme_get_setting('if_subfooter_link_5');
}
/**
* A helper function to transform the site name into a machine safe name.
*
* This is used in the ilw-header and ilw-footer as a source attribute.
*
* @return string
* The cleaned site name string.
*/
function get_clean_system_site_name() {
$name = Drupal::config('system.site')->get('name');
// Replaces:
// Ampersand to "and".
$name = preg_replace('/[&]/u', 'and', $name);
// Dashes and spaces to an underscore.
$name = preg_replace('/[- ]/u', '_', $name);
// Any non-alphanumeric with nothing.
$name = preg_replace('/[^_a-zA-Z0-9]/u', '', $name);
// And then:
// Make string all lowercase.
$name = strtolower($name);
return $name;
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for page.html.twig.
*/
function illinois_framework_theme_theme_suggestions_page_alter(array &$suggestions, array $variables, $hook) {
// Error page template suggestions.
$exception = Drupal::requestStack()->getCurrentRequest()->attributes->get('exception');
if ($exception !== NULL) {
$status_code = $exception->getStatusCode();
$suggestions[] = 'page__' . (string) $status_code;
}
// Provide page template suggestions per content type.
$node = \Drupal::routeMatch()->getParameter('node') ?: \Drupal::routeMatch()->getParameter('node_preview');
if ($node instanceof NodeInterface) {
$suggestions[] = 'page__' . $node->bundle();
}
}
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*
* Pass block region value to content so this can be used in
* illinois_framework_theme_theme_suggestions_menu_alter.
*/
function illinois_framework_theme_preprocess_block(&$variables) {
if (isset($variables['elements']['#id'])) {
$block_entity = Block::load($variables['elements']['#id']);
if ($block_entity) {
$region = $block_entity->getRegion();
$variables['content']['#attributes']['region'] = $region;
}
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for menu.html.twig.
*
* Provide region based menu suggestions.
*/
function illinois_framework_theme_theme_suggestions_menu_alter(array &$suggestions, array $variables) {
if (isset($variables['attributes']['region'])) {
$suggestion = 'menu__' . $variables['menu_name'] . '__' . $variables['attributes']['region'];
$suggestions[] = str_replace('-', '_', $suggestion);
}
}
/**
* Adds a button class to the UofI login button
*
* @param $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $form_id
*/
function illinois_framework_theme_form_user_login_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Log in'),
'#attributes' => array('class' => array('btn--login')),
];
if (isset($form['simplesamlphp_auth_login_link'])) {
$form['simplesamlphp_auth_login_link']['#attributes']['class'] = 'ilw-button ilw-theme-orange-solid ilw-button-large simplesamlphp-auth-login-link';
$form['simplesamlphp_auth_login_link']['#weight'] = -100; // Ensure the button appears before the standard submit button.
$form['simplesamlphp_auth_login_link']['#suffix'] = '<h2 class="local-login">' . t('Admin Login') . '</h2>';
$form['simplesamlphp_auth_login_link']['#attributes']['autofocus'] = 'autofocus';
if (isset($form['name'])) {
unset($form['name']['#attributes']['autofocus']);
}
}
}
/**
* Implements hook_preprocess_HOOK() for page.html.twig.
*
* This function handles multiple responsibilities related to page preprocessing:
* - Puts "full width" paragraphs into a page-level variable so they can be rendered in a different part of the template.
* - Adding a class to the body for 404 pages.
* - Managing the logic for showing/hiding the sidebar based on node fields.
*
*/
function illinois_framework_theme_preprocess_page(array &$variables): void {
//adds a class to 404 page to control margins
if (\Drupal::routeMatch()->getRouteName() === 'system.404') {
$variables['attributes']['class'][] = 'is-404';
}
// Get the current node from the route match.
$route_match = \Drupal::routeMatch();
$node = $route_match->getParameter('node') ?: $route_match->getParameter('node_preview');
// Ensure 'node' is available in the page template (especially for previews).
if ($node instanceof NodeInterface && !isset($variables['node'])) {
$variables['node'] = $node;
}
// Handle preview specific logic.
$variables['is_preview'] = $route_match->getRouteName() === 'entity.node.preview';
// The default is to show the sidebar unless the node has a field_sidebar value of 'nosidebar'
$variables['show_sidebar'] = TRUE;
$variables['node_has_sidebar'] = TRUE;
if ($node instanceof NodeInterface) {
// Determine if the sidebar should be hidden
if ($node->hasField('field_sidebar') && !$node->get('field_sidebar')->isEmpty()) {
$sidebar_value = $node->get('field_sidebar')->value;
if ($sidebar_value === 'nosidebar') {
$variables['show_sidebar'] = FALSE;
$variables['node_has_sidebar'] = FALSE;
}
}
// During preview, if sidebar_first is empty but we expect a sidebar,
// manually inject the menu tree into the region.
if ($variables['is_preview'] && empty($variables['page']['sidebar_first']) && $variables['node_has_sidebar']) {
$menu_build = _illinois_framework_theme_get_preview_sidebar_menu($node);
if (!empty($menu_build)) {
$variables['page']['sidebar_first']['sidenavigation'] = $menu_build;
}
}
// Only proceed with paragraph splitting if it is a content_page and sidebar mode is active.
if ($node->bundle() === 'content_page' && $variables['node_has_sidebar']) {
// Determine the split point.
$split_at = 0;
if ($node->hasField('field_sidebar_paragraphs') && !$node->get('field_sidebar_paragraphs')->isEmpty()) {
$split_at = (int) $node->get('field_sidebar_paragraphs')->value;
}
// Check if the paragraph field exists.
if ($node->hasField('field_paragraph') && !$node->get('field_paragraph')->isEmpty()) {
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('paragraph');
$full_width_render = [];
$items = $node->get('field_paragraph')->referencedEntities();
// Build individual render arrays for the paragraphs that should be full-width.
foreach ($items as $index => $paragraph) {
if ($index >= $split_at) {
$full_width_render[] = $view_builder->view($paragraph, 'full');
}
}
// Assign the clean list of render arrays to the page-level variable.
if (!empty($full_width_render)) {
$variables['page']['full_width_paragraphs'] = $full_width_render;
}
}
}
}
}
/**
* Helper function to retrieve the sidebar menu render array during previews.
*
* @param \Drupal\node\NodeInterface $node
* The node currently being previewed.
*
* @return array
* A render array representing the active menu trail, or an empty array.
*/
function _illinois_framework_theme_get_preview_sidebar_menu(NodeInterface $node): array {
$menu_name = 'main';
$parent_id = NULL;
// 1. Try to get menu parent from node's unsaved menu settings.
if (isset($node->menu) && is_array($node->menu) && !empty($node->menu['enabled'])) {
$menu_name = $node->menu['menu_name'] ?? 'main';
$parent_id = $node->menu['parent'] ?? NULL;
if ($parent_id && str_contains($parent_id, ':')) {
// The parent string often contains the menu name prefix (e.g. 'main:plugin_id').
$parts = explode(':', $parent_id, 2);
$parent_id = $parts[1] ?? NULL;
}
}
// 2. Fallback: Search existing links for this node via the link manager.
if (!$parent_id && $node->id()) {
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$links = $menu_link_manager->loadLinksByRoute('entity.node.canonical', ['node' => $node->id()]);
if ($links) {
$link = reset($links);
$parent_id = $link->getParent();
$menu_name = $link->getMenuName();
// If the node itself is at level 1, use its own link as root to show children.
if (!$parent_id) {
$parent_id = $link->getPluginId();
}
}
}
$menu_tree = \Drupal::menuTree();
$parameters = new MenuTreeParameters();
if ($parent_id) {
$parameters->setRoot($parent_id);
$parameters->excludeRoot();
$parameters->setActiveTrail([$parent_id]);
}
else {
// 3. Last resort fallback: Show the top levels of the main menu.
$parameters->setMaxDepth(2);
}
$tree = $menu_tree->load($menu_name, $parameters);
$manipulators = [
['callable' => 'menu.default_tree_manipulators:checkAccess'],
['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
];
$tree = $menu_tree->transform($tree, $manipulators);
if (!empty($tree)) {
$menu_build = $menu_tree->build($tree);
// Enforce the specific theme suggestion for the sidebar navigation block.
// The double 'menu__' matches the template file 'menu--menu--side-bar-first.html.twig'.
$menu_build['#theme'] = 'menu__menu__side_bar_first';
$menu_build['#menu_name'] = $menu_name;
return $menu_build;
}
return [];
}
/**
* Implements hook_preprocess_HOOK() for node.html.twig.
*
* This function handles the logic for splitting paragraphs into main content
* and sidebar based on the node's field_sidebar_paragraphs value, but only if
* the sidebar is active. It also ensures this logic only runs in 'full' or
* 'preview' view modes to avoid unintended consequences in teasers or other
* view modes.
*/
function illinois_framework_theme_preprocess_node(array &$variables): void {
$node = $variables['node'];
$node_has_sidebar = TRUE;
if ($node->hasField('field_sidebar') && !$node->get('field_sidebar')->isEmpty()) {
if ($node->get('field_sidebar')->value === 'nosidebar') {
$node_has_sidebar = FALSE;
}
}
// Only remove paragraphs from the main content if it's a content_page in full or preview mode, and the sidebar is active.
if ($node->bundle() === 'content_page' && ($variables['view_mode'] === 'full' || $variables['view_mode'] === 'preview')) {
// If sidebar mode is active, hide the paragraphs that were moved to the page variable.
if ($node_has_sidebar) {
$split_at = 0;
if ($node->hasField('field_sidebar_paragraphs') && !$node->get('field_sidebar_paragraphs')->isEmpty()) {
$split_at = (int) $node->get('field_sidebar_paragraphs')->value;
}
if (isset($variables['content']['field_paragraph'])) {
$children = Element::children($variables['content']['field_paragraph']);
foreach ($children as $index => $key) {
// Remove paragraphs from index $split_at and beyond.
if ($index >= $split_at) {
unset($variables['content']['field_paragraph'][$key]);
}
}
}
}
}
}
/**
* Implements hook_preprocess_HOOK() for menu_local_tasks.
*
* Remove the "Delete" tab from the local tasks (tabs).
*/
function illinois_framework_theme_preprocess_menu_local_tasks(&$variables) {
foreach (['primary', 'secondary'] as $type) {
if (!empty($variables[$type])) {
foreach (\Drupal\Core\Render\Element::children($variables[$type]) as $key) {
// Hide standard entity delete form tabs
if (strpos((string) $key, 'delete_form') !== FALSE) {
unset($variables[$type][$key]);
continue;
}
// Additional check by route name just in case the key differs
if (isset($variables[$type][$key]['#link']['url'])) {
$url = $variables[$type][$key]['#link']['url'];
if ($url instanceof \Drupal\Core\Url) {
$route_name = $url->getRouteName();
if (strpos($route_name, '.delete_form') !== FALSE) {
unset($variables[$type][$key]);
}
}
}
}
}
}
}
/**
* Implements hook_preprocess_HOOK() for menu.html.twig.
*
* Add the parent item to the template for the side navigation.
*/
function illinois_framework_theme_preprocess_menu(array &$variables) {
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$first = reset($variables['items']);
if ($first && isset($first['original_link'])) {
$item = $first['original_link'];
// If the first item has a parent, add that parent to the template so we
// can render it in the same list.
if ($item?->getParent()) {
/** @var \Drupal\Core\Utility\LinkGenerator $link_generator */
$link_generator = \Drupal::service('link_generator');
$parent = $menu_link_manager->createInstance($item->getParent());
$variables['parent_name'] = $parent->getTitle();
$variables['parent_url'] = $parent->getUrlObject();
// Required for Drupal to manage the aria-current attribute.
$variables['parent_url']->setOption('set_active_class', TRUE);
$variables['parent_url']->setOption('attributes', ['class' => ['ilw-section-nav--root']]);
// Create the render array we'll use in the template.
$variables['parent_a'] = $link_generator->generate($parent->getTitle(), $variables['parent_url']);
}
}
}
/**
* Implements hook_preprocess_HOOK() for paragraph.html.twig.
*
* This function handles propagating background colors from parent paragraphs
* (like bb and icon_row) to their children, and maps icon keys to CSS classes.
*/
function illinois_framework_theme_preprocess_paragraph(array &$variables) {
$paragraph = $variables['paragraph'] ?? ($variables['elements']['#paragraph'] ?? NULL);
if (!$paragraph instanceof ParagraphInterface) {
return;
}
// --- Background propagation for bb_content and icon_row_content ---
// This code passes the background color setting from the parent
// paragraph down to the child paragraph.
$bundle = $paragraph->bundle();
if ($bundle === 'bb_content' || $bundle === 'icon_row_content') {
$parent = $paragraph->getParentEntity();
if ($parent instanceof ParagraphInterface && ($parent->bundle() === 'bb' || $parent->bundle() === 'icon_row')) {
if ($parent->bundle() === 'bb' && $parent->hasField('field_bb_background') && !$parent->get('field_bb_background')->isEmpty()) {
$variables['bb_background'] = $parent->get('field_bb_background')->value;
}
elseif ($parent->bundle() === 'icon_row' && $parent->hasField('field_icon_row_background') && !$parent->get('field_icon_row_background')->isEmpty()) {
$variables['bb_background'] = $parent->get('field_icon_row_background')->value;
}
else {
$variables['bb_background'] = 'white';
}
}
else {
// Fallback default when no suitable parent is found.
$variables['bb_background'] = 'white';
}
}
// --- Icon mapping for paragraph cta and icon_row_content ---
if ($bundle === 'cta' || $bundle === 'icon_row_content') {
$icon_key = '';
if ($paragraph->hasField('field_icon_row_content_icon') && !$paragraph->get('field_icon_row_content_icon')->isEmpty()) {
$first = $paragraph->get('field_icon_row_content_icon')->first();
if ($first) {
$val = $first->getValue();
$icon_key = (string) ($val['value'] ?? $val['target_id'] ?? '');
}
}
$icon_map = [
'il-icon-admissions' => 'admissions-line',
'il-icon-alumni' => 'alumni-line',
'il-icon-apply-now' => 'apply-now-line',
'il-icon-audio' => 'audio-line',
'audio-transcript' => 'audio-transcript-line',
'il-icon-back' => 'back-line',
'bluesky' => 'bluesky-line',
'il-icon-calendar' => 'calendar-line',
'il-icon-cancel-exit' => 'cancel-line',
'check' => 'check-line',
'il-icon-comment' => 'comment-line',
'il-icon-directory' => 'directory-line',
'il-icon-document' => 'document-line',
'il-icon-donor' => 'donor-line',
'il-icon-download' => 'download-line',
'il-icon-email' => 'email-line',
'il-icon-event' => 'event-line',
'il-icon-facebook' => 'facebook-line',
'il-icon-faculty-staff' => 'faculty-line',
'faq' => 'faq-line',
'il-icon-favorite' => 'favorite-line',
'flickr' => 'flickr-line',
'github' => 'github-line',
'il-icon-give-gift' => 'gift-line',
'il-icon-google-plus' => 'google-plus-line',
'il-icon-handbook-manual'=> 'handbook-line',
'il-icon-home' => 'home-line',
'il-icon-hours' => 'hours-line',
'il-icon-hr' => 'hr-line',
'il-icon-image' => 'image-line',
'il-icon-inclusive' => 'inclusive-line',
'il-icon-info' => 'info-line',
'il-icon-instagram' => 'instagram-line',
'il-icon-intranet' => 'intranet-line',
'il-icon-job-employment'=> 'employment-line',
'il-icon-less' => 'less-line',
'il-icon-link' => 'link-line',
'il-icon-linkedin' => 'linkedin-line',
'il-icon-location' => 'location-line',
'mastodon' => 'mastodon-line',
'il-icon-menu' => 'menu-line',
'il-icon-more' => 'more-line',
'il-icon-news' => 'news-line',
'il-icon-next' => 'next-line',
'il-icon-notification' => 'notification-line',
'il-icon-parent-family' => 'family-line',
'il-icon-partners' => 'partners-line',
'il-icon-pay-bill' => 'pay-line',
'pause' => 'pause-line',
'pdf' => 'pdf-line',
'play' => 'play-line',
'il-icon-phone-call' => 'phone-line',
'il-icon-pinterest' => 'pinterest-line',
'il-icon-plan' => 'plan-line',
'il-icon-program-of-study'=> 'program-of-study-line',
'reddit' => 'reddit-line',
'il-icon-research' => 'research-line',
'il-icon-resources' => 'resources-line',
'il-icon-safety' => 'safety-line',
'il-icon-search' => 'search-line',
'il-icon-send' => 'send-line',
'il-icon-settings' => 'settings-line',
'il-icon-shop' => 'shop-line',
'il-icon-sitemap' => 'sitemap-line',
'il-icon-snapchat' => 'snapchat-line',
'spotify' => 'spotify-line',
'il-icon-students' => 'students-line',
'il-icon-submit' => 'submit-line',
'il-icon-team' => 'team-line',
'threads' => 'threads-line',
'tiktok' => 'tiktok-line',
'il-icon-tickets' => 'tickets-line',
'il-icon-trash' => 'trash-line',
'il-icon-twitter' => 'twitter-line',
'il-icon-unit' => 'unit-line',
'il-icon-user' => 'user-line',
'il-icon-video' => 'video-line',
'il-icon-volume' => 'volume-line',
'il-icon-website' => 'website-line',
'il-icon-weibo' => 'weibo-line',
'il-icon-whatsapp' => 'whatsapp-line',
'il-icon-workshop-training'=> 'workshop-line',
'x' => 'x-line',
'yelp' => 'yelp-line',
'il-icon-youtube' => 'youtube-line',
];
$variables['cta_icon'] = $icon_map[$icon_key] ?? '';
}
}
/**
* Implements hook_preprocess_HOOK() for breadcrumb.html.twig.
*/
function illinois_framework_theme_preprocess_breadcrumb(array &$variables) {
if ($variables['breadcrumb']) {
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
if (!empty($page_title)) {
$variables['breadcrumb'][] = [
'text' => $page_title,
'attributes' => new Attribute(['class' => ['active']]),
];
}
}
}
/**
* Implements hook_preprocess_HOOK() for paragraph--feature-split.html.twig.
*/
function illinois_framework_theme_preprocess_paragraph__feature_split(array &$variables) {
$paragraph = $variables['paragraph'];
// Reverse attribute.
$variables['reverse'] = FALSE;
if (!$paragraph->field_feature_split_img_align->isEmpty()) {
$variables['reverse'] = $paragraph->field_feature_split_img_align->value === 'right';
}
// Max width class.
$variables['max_width_class'] = 'full-width';
if (!$paragraph->field_feature_split_img_width->isEmpty()) {
if ($paragraph->field_feature_split_img_width->value === 'fixed') {
$variables['max_width_class'] = 'fixed-width';
}
}
// Ensure the class is added to the renderable attributes and classes array
if (empty($variables['attributes']) || !($variables['attributes'] instanceof Attribute)) {
$variables['attributes'] = new Attribute();
}
$variables['attributes']->addClass($variables['max_width_class']);
if (empty($variables['classes']) || !is_array($variables['classes'])) {
$variables['classes'] = [];
}
$variables['classes'][] = $variables['max_width_class'];
// Theme.
$variables['theme'] = '';
if (!$paragraph->field_feature_split_background->isEmpty()) {
$background_value = $paragraph->field_feature_split_background->value;
switch ($background_value) {
case 'illiniblue':
$variables['theme'] = 'blue';
break;
case 'bluegradient':
$variables['theme'] = 'blue-gradient';
break;
case 'orangegradient':
$variables['theme'] = 'orange-gradient';
break;
default:
$variables['theme'] = $background_value;
}
}
}
/**
* Implements hook_preprocess_HOOK() for paragraph--accordion-content.html.twig.
*/
function illinois_framework_theme_preprocess_paragraph__accordion_content(array &$variables) {
$variables['has_parent_title'] = FALSE;
$paragraph = $variables['paragraph'] ?? NULL;
if (!$paragraph instanceof ParagraphInterface) {
return;
}
$parent = $paragraph->getParentEntity();
if (!$parent instanceof ParagraphInterface) {
return;
}
if ($parent->hasField('field_accordion_title') && !$parent->get('field_accordion_title')->isEmpty()) {
$variables['has_parent_title'] = TRUE;
}
}
/**
* Implements hook_preprocess_HOOK() for field.html.twig.
*/
function illinois_framework_theme_preprocess_field(array &$variables) {
// 1. Check if we are dealing with the 'body' field on a 'node' entity.
// This implicitly excludes paragraphs or blocks that might also have a body field.
if ($variables['entity_type'] === 'node' && $variables['field_name'] === 'body') {
$view_mode = $variables['element']['#view_mode'];
if ($view_mode === 'default' || $view_mode === 'full') {
// Inject the custom CSS class into the field's wrapper attributes.
// Ensure the attributes object exists and is an Attribute instance (usually is).
if (!isset($variables['attributes']['class'])) {
$variables['attributes']['class'] = [];
}
$variables['attributes']['class'][] = 'node-body-field-full-display';
}
}
}
/**
* Implements hook_preprocess_HOOK() for region.html.twig.
*
* This adds a variable to identify if the current page is the front page, which can be used for conditional logic in region templates.
*/
function illinois_framework_theme_preprocess_region(array &$variables): void {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}