This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
civictheme.theme
233 lines (211 loc) · 7.32 KB
/
civictheme.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
<?php
/**
* @file
* Functions to support theming in the CivicTheme theme.
*/
use Drupal\civictheme\CivicthemeConstants;
require_once 'includes/utilities.inc';
require_once 'includes/process.inc';
require_once 'includes/accordion.inc';
require_once 'includes/alert.inc';
require_once 'includes/attachment.inc';
require_once 'includes/banner.inc';
require_once 'includes/block_content.inc';
require_once 'includes/callout.inc';
require_once 'includes/campaign.inc';
require_once 'includes/content.inc';
require_once 'includes/manual_list.inc';
require_once 'includes/cards.inc';
require_once 'includes/form.inc';
require_once 'includes/iframe.inc';
require_once 'includes/image.inc';
require_once 'includes/link.inc';
require_once 'includes/automated_list.inc';
require_once 'includes/local_tasks.inc';
require_once 'includes/libraries.inc';
require_once 'includes/map.inc';
require_once 'includes/media.inc';
require_once 'includes/menu.inc';
require_once 'includes/mobile_navigation.inc';
require_once 'includes/next_step.inc';
require_once 'includes/node.inc';
require_once 'includes/page.inc';
require_once 'includes/pager.inc';
require_once 'includes/paragraphs.inc';
require_once 'includes/primary_navigation.inc';
require_once 'includes/promo.inc';
require_once 'includes/quote.inc';
require_once 'includes/search.inc';
require_once 'includes/secondary_navigation.inc';
require_once 'includes/system_main_block.inc';
require_once 'includes/site_section.inc';
require_once 'includes/skip_link.inc';
require_once 'includes/slider.inc';
require_once 'includes/snippet.inc';
require_once 'includes/social_links.inc';
require_once 'includes/system_branding.inc';
require_once 'includes/table.inc';
require_once 'includes/views.inc';
require_once 'includes/wysiwyg.inc';
require_once 'includes/webform.inc';
/**
* Implements hook_theme().
*
* @phpstan-ignore-next-line
*/
function civictheme_theme(): array {
// Components from the library are used directly by including them within
// existing templates.
//
// However, in some rare cases we still need to define custom themes to allow
// component reuse outside the library.
//
// The list below may be reduced further upon architectural review and
// adjustments within the library.
return [
'civictheme_basic_content' => [
'variables' => [
'component_theme' => CivicthemeConstants::THEME_LIGHT,
'content' => '',
],
'template' => 'misc/basic-content',
],
'civictheme_tag_list' => [
'variables' => [
'tags' => [],
'vertical_spacing' => NULL,
'content_top' => NULL,
'content_bottom' => NULL,
'modifier_class' => NULL,
],
'template' => 'misc/tag-list',
],
];
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function civictheme_theme_suggestions_block_alter(array &$suggestions, array $variables): void {
// Add theme suggestions to all blocks whose bundle starts with 'civictheme_'.
if (!empty($variables['elements']['#base_plugin_id']) && $variables['elements']['#base_plugin_id'] == 'block_content') {
$entity = $variables['elements']['content']['#block_content'] ?? NULL;
if ($entity && strpos($entity->bundle(), 'civictheme_') === 0) {
$suggestions[] = 'block__' . $entity->bundle() . '__default';
}
}
}
/**
* Implements hook_theme_registry_alter().
*/
function civictheme_theme_registry_alter(array &$theme_registry): void {
// Define a new preprocess hook that will always run last.
$hook = 'civictheme_preprocess_last';
foreach ($theme_registry as $name => $info) {
if (in_array($hook, $theme_registry[$name]['preprocess functions'] ?? [])) {
foreach ($info['preprocess functions'] as $k => $function) {
if ($function == $hook) {
unset($theme_registry[$name]['preprocess functions'][$k]);
$theme_registry[$name]['preprocess functions'][] = $hook;
}
}
}
else {
$theme_registry[$name]['preprocess functions'][] = $hook;
}
}
}
/**
* Implements hook_preprocess_last().
*/
function civictheme_preprocess_last(array &$variables, string $hook): void {
// Process attributes for all components before they are sent to templates.
civictheme_convert_attributes_to_modifier_class($variables);
}
/**
* Implements hook_preprocess_HOOK().
*/
function civictheme_preprocess_html(array &$variables): void {
_civictheme_preprocess_html__skip_link($variables);
_civictheme_preprocess_html__site_section($variables);
// Disable modifier_class as this template is provided by Drupal.
$variables['modifier_class'] = FALSE;
}
/**
* Implements hook_preprocess_HOOK().
*/
function civictheme_preprocess_page(array &$variables): void {
// All pages.
_civictheme_preprocess_page($variables);
// Node pages.
_civictheme_preprocess_page__node($variables);
// Preprocessing for Alerts functionality.
_civictheme_preprocess_page__civictheme_alert($variables);
// Add all page variables to the root variables. This is required so that
// child themes could add page-level variables without have to extend page
// template (the variables there are not scoped as an exception).
//
// IMPORTANT! Do not add anything below this line or components will not be
// able to discover variables.
$page_variables = array_filter($variables['page'], function ($key): bool {
return strpos($key, '#') !== 0;
}, ARRAY_FILTER_USE_KEY);
$variables += $page_variables;
}
/**
* Implements hook_preprocess_HOOK().
*/
function civictheme_preprocess_node(array &$variables): void {
// All nodes.
_civictheme_preprocess_node($variables);
// Preprocessing for each node view mode.
$view_mode = $variables['elements']['#view_mode'] ?? NULL;
if ($view_mode) {
$preprocessor_function = '_civictheme_preprocess_node__' . $view_mode;
if (function_exists($preprocessor_function)) {
$preprocessor_function($variables);
}
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function civictheme_preprocess_block(array &$variables): void {
_civictheme_preprocess_block__system_main_block($variables);
_civictheme_preprocess_block__civictheme_banner($variables);
_civictheme_preprocess_block__navigation($variables);
_civictheme_preprocess_block__civictheme_footer_menu($variables);
_civictheme_preprocess_block__content($variables);
_civictheme_preprocess_block__civictheme_mobile_navigation($variables);
_civictheme_preprocess_block__civictheme_social_links($variables);
}
/**
* Implements template_preprocess_image().
*/
function civictheme_preprocess_image(array &$variables): void {
_civictheme_preprocess_image($variables);
}
/**
* Implement template_preprocess_menu_local_tasks().
*/
function civictheme_preprocess_menu_local_tasks(array &$variables): void {
_civictheme_preprocess_menu_local_tasks($variables);
}
/**
* Implements template_preprocess_menu().
*/
function civictheme_preprocess_menu(array &$variables): void {
_civictheme_preprocess_menu_items($variables['items']);
}
/**
* Implements template_preprocess_field().
*/
function civictheme_preprocess_field(array &$variables): void {
_civictheme_preprocess_wysiwyg_field($variables);
_civictheme_preprocess_date_range_field($variables);
}
/**
* Implements hook_library_info_alter().
*/
function civictheme_library_info_alter(array &$libraries, string $extension): void {
_civictheme_library_info_alter__color_selector($libraries, $extension);
}