generated from SU-SWS/stanford_starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppo_irsr_subtheme.theme
executable file
·126 lines (107 loc) · 4.09 KB
/
ppo_irsr_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
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* @file
* Preprocess functions for IRSR Subtheme.
*/
use Drupal\node\NodeInterface;
/**
* Prepares variables for the html.html.twig template.
*/
function ppo_irsr_subtheme_preprocess_html(&$variables) {
$variables['stanford_basic_path'] = \Drupal::service('extension.list.theme')->getPath('stanford_basic');
}
/**
* Implements hook_preprocess_HOOK().
*/
function ppo_irsr_subtheme_preprocess_page(&$variables) {
if (
isset($variables['node']) &&
$variables['node'] instanceof NodeInterface &&
$variables['node']->bundle() == 'stanford_page' &&
$variables['node']->hasField('layout_selection') &&
$variables['node']->get('layout_selection')->getString() == 'stanford_basic_page_full'
) {
$variables['#attached']['library'][] = 'ppo_irsr_subtheme/basic-page-full-width';
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function ppo_irsr_subtheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (!empty($variables['elements']['#id']) && $variables['elements']['#id'] == 'ppo_irsr_subtheme_search') {
$suggestions[] = 'block__stanford_basic_search';
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function ppo_irsr_subtheme_preprocess_ds_entity_view(&$variables) {
// if not running on a paragraph, exit out.
if (!isset($variables['content']['#paragraph'])) {
return;
}
$paragraph = $variables['content']['#paragraph'];
// Process Banners
if ($paragraph->bundle() == 'stanford_banner') {
ppo_irsr_subtheme_preprocess_banner($variables);
}
// Process Cards
if ($paragraph->bundle() == 'stanford_card') {
ppo_irsr_subtheme_preprocess_card($variables);
}
}
/**
* Implements hook_preprocess_banner().
*/
function ppo_irsr_subtheme_preprocess_banner(&$variables) {
$paragraph = $variables['content']['#paragraph'];
// Add banner variant style class to card wrapper.
$variables['attributes']['class'][] = $paragraph->getBehaviorSetting('react_paragraphs:banner_variant_info', 'banner_style');
}
/**
* Implements hook_preprocess_card().
*/
function ppo_irsr_subtheme_preprocess_card(&$variables) {
$paragraph = $variables['content']['#paragraph'];
// Add variant style class to card wrapper.
$variables['attributes']['class'][] = $paragraph->getBehaviorSetting('react_paragraphs:card_variant_info', 'card_color');
}
/**
* Implements hook_preprocess_lists().
*/
function ppo_irsr_subtheme_preprocess_paragraph__stanford_lists(array &$variables): void {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = &$variables['paragraph'];
$existing_classes = $variables['attributes']['class'] ?? [];
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:lists_variant_info', 'cards_color'),
$paragraph->getBehaviorSetting('react_paragraphs:lists_variant_info', 'grid_rows'),
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}
/**
* Implements hook_preprocess_entity().
*/
function ppo_irsr_subtheme_preprocess_paragraph__stanford_entity(array &$variables): void {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
$paragraph = &$variables['paragraph'];
$existing_classes = $variables['attributes']['class'] ?? [];
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:entity_variant_info', 'cards_color'),
$paragraph->getBehaviorSetting('react_paragraphs:entity_variant_info', 'grid_rows'),
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}
/**
* Implements hook_preprocess_paragraph__stanford_layout().
*/
function ppo_irsr_subtheme_preprocess_paragraph__stanford_layout(array &$variables): void {
/** @var \Drupal\paragraphs\Layout\Paragraph $paragraph */
$paragraph = &$variables['paragraph'];
$existing_classes = $variables['attributes']['class'] ?? [];
$extra_classes = [
$paragraph->getBehaviorSetting('react_paragraphs:layout_variant_info', 'padding_bottom'),
$paragraph->getBehaviorSetting('react_paragraphs:layout_variant_info', 'section_color'),
];
$variables['attributes']['class'] = array_merge($existing_classes, $extra_classes);
}