forked from SU-SWS/lbretransportation_subtheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlbretransportation_subtheme.theme
executable file
·113 lines (99 loc) · 4.08 KB
/
lbretransportation_subtheme.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
<?php
/**
* @file
* Preprocess functions for Stanford Starter.
*/
use Drupal\ui_patterns\Element\PatternContext;
/**
* Prepares variables for the html.html.twig template.
*/
function lbretransportation_subtheme_preprocess_html(&$variables) {
$variables['stanford_basic_path'] = \Drupal::service('extension.list.theme')
->getPath('stanford_basic');
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function lbretransportation_subtheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (!empty($variables['elements']['#id']) && $variables['elements']['#id'] == 'lbretransportation_subtheme_search') {
$suggestions[] = 'block__stanford_basic_search';
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function lbretransportation_subtheme_preprocess_pattern_hero(array &$variables): void {
/** @var \Drupal\ui_patterns\Element\PatternContext $context */
$context = &$variables['context'];
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = $context->getProperty('entity');
if ($paragraph) {
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:banner_style', 'layout', 'layout--default'),
$paragraph->getBehaviorSetting('react_paragraphs:banner_style', 'color_scheme', 'color--cardinal-red'),
];
/** @var \Drupal\Core\Template\Attribute $attributes */
$attributes = &$variables['attributes'];
$attributes->addClass($extra_classes);
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function lbretransportation_subtheme_preprocess_paragraph__stanford_lists(array &$variables): void {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = &$variables['paragraph'];
$existing_classes = $variables['attributes']['class'] ?? [];
if ($paragraph) {
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:lists_style', 'cards_color', 'cards-color--light'),
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function lbretransportation_subtheme_preprocess_paragraph__stanford_wysiwyg(array &$variables): void {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = &$variables['paragraph'];
$existing_classes = $variables['attributes']['class'] ?? [];
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:wysiwyg_style', 'style', 'style--default'),
$paragraph->getBehaviorSetting('react_paragraphs:wysiwyg_style', 'color_scheme', 'color--default'),
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}
/**
* Implements hook_ui_patterns_suggestions_alter().
*/
function lbretransportation_subtheme_ui_patterns_suggestions_alter(array &$suggestions, array $variables, PatternContext $context): void {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
// Replace dash with underscore from the theme suggestions array in order for the templates to work properly.
foreach ($suggestions as &$value) {
$value = str_replace('-', '_', $value);
}
// Unset the reference to avoid potential side effects.
unset($value);
$paragraph = $context->getProperty('entity');
if ($paragraph && $paragraph->bundle() === "stanford_banner") {
$layout = $paragraph->getBehaviorSetting('react_paragraphs:banner_style', 'layout', 'layout--default');
$suggestions[] = $variables['theme_hook_original'] . '__layout_' . str_replace('-', '_', $layout);
// Add variant preview theme suggestion.
if ($context->isOfType('preview')) {
$suggestions[] = $variables['theme_hook_original'] . '__layout_' . str_replace('-', '_', $layout) . '__preview';
}
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function lbretransportation_subtheme_preprocess(&$variables, $hook) {
if ($hook == "pattern_news-vertical-teaser") {
$node = $variables["context"]->getProperty('entity');
// Add date to the card.
if ($node && !$node->get('su_news_publishing_date')->isEmpty()) {
$variables['news_publishing_date'] = $node->su_news_publishing_date->date->format('F d, Y');
}
}
}