-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffw_theme.theme
executable file
·245 lines (217 loc) · 8.01 KB
/
ffw_theme.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
<?php
/**
* @file
* Functions to support theming in ffw_theme theme.
*/
use Drupal\Core\Url;
use Drupal\node\NodeInterface;
use Drupal\views\Views;
use Drupal\Core\Form\FormState;
/**
* Implements hook_theme_suggestions_HOOK_alter() for page templates.
*/
function ffw_theme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if (!in_array('page__front', $suggestions, TRUE)) {
/** @var \Drupal\node\Entity\Node $node */
if ($node = \Drupal::routeMatch()->getParameter('node')) {
if ($node instanceof NodeInterface) {
$content_type = $node->bundle();
if ($content_type) {
array_unshift($suggestions, 'page__type_' . $content_type);
}
}
}
}
$route_name = \Drupal::routeMatch()->getRouteName();
switch ($route_name) {
case 'system.403':
$suggestions[] = 'page__403';
break;
case 'system.404':
$suggestions[] = 'page__404';
break;
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for taxonomy templates.
*/
function ffw_theme_theme_suggestions_taxonomy_term_alter(array &$suggestions, array $variables, $hook) {
if ($hook === 'taxonomy_term') {
/** @var \Drupal\taxonomy\Entity\Term $term */
$term = $variables['elements']['#taxonomy_term'];
$suggestions[] = "{$hook}__{$term->bundle()}__{$variables['elements']['#view_mode']}";
}
}
/**
* Implements hook_preprocess_html().
*/
// function ffw_theme_preprocess_html(&$variables) {
// $node = \Drupal::routeMatch()->getParameter('node');
// if ($node instanceof NodeInterface) {
// // Example for adding variables
// if ($node->getType() === 'article') {
// $variables['#attached']['library'][] = 'ffw_theme/article';
// $variables['attributes']['class'][] = 'test';
// }
// }
// }
/**
* Implements hook_preprocess_page().
*/
// function ffw_theme_preprocess_page(&$variables) {
// if ($var === 'value') {
// $variables['variable'] = TRUE;
// }
// }
/**
* Implements hook_preprocess_media().
*/
// function ffw_theme_preprocess_media(&$variables) {
// /** @var \Drupal\media\Entity\Media $media */
// $media = $variables['media'];
// $bundle = $media->bundle();
// if ($bundle === 'video') {
// // We just set the video url so it can be used in the twig template.
// $variables['video_embed_url'] = $media->field_media_oembed_video->value;
// }
// }
/**
* Implements hook_preprocess_HOOK().
*/
// function ffw_theme_preprocess_paragraph(&$variables) {
// /** @var \Drupal\paragraphs\Entity\Paragraph $paragraph */
// $paragraph = $variables['paragraph'];
// $bundle = $paragraph->bundle();
// // Example:
// // if ($bundle === 'PARAGRAPH_MACHINE_NAME') {
// // $variables['attributes']['class'][] = $class;
// // $variables['#attached']['library'][] = 'ffw_theme/text';
// // }
// }
/**
* Implements hook_theme_suggestions_form_alter().
*/
function ffw_theme_theme_suggestions_form_alter(array &$suggestions, array $variables) {
$suggestions[] = 'form__' . $variables['element']['#form_id'];
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
// function ffw_theme_theme_suggestions_fieldset_alter(array &$suggestions, array $variables) {
// if (isset($variables['element']['#type'])) {
// $suggestions[] = 'fieldset__' . $variables['element']['#type'];
// if (isset($variables["element"]["#name"])) {
// $suggestions[] = 'fieldset__' . $variables['element']['#type'] . '__' . $variables["element"]["#name"];
// }
// }
// if (isset($variables['element']['#context']['#view_id'])) {
// $suggestions[] = 'fieldset__' . $variables['element']['#context']['#view_id'] . '__' . $variables['element']['#type'] . '__' . $variables['element']['#name'];
// }
// }
/**
* Implements hook_theme_suggestions_field_alter().
*/
function ffw_theme_theme_suggestions_field_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
$suggestions[] = 'field__' . $element['#entity_type'] . '__' . $element['#bundle'] . '__' . $element['#view_mode'] . '__' . $element['#field_name'];
}
/**
* Provide active language code for the language switcher.
*/
function ffw_theme_preprocess_links__language_block(&$variables) {
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
$variables['active_language'] = $language_interface->getId();
}
/**
* Open file link in a new tab.
*/
// function ffw_theme_preprocess_file_link(&$variables) {
// if ($variables['link'] && $variables['link']['#url'] instanceof Url) {
// $options = $variables['link']['#url']->getOptions('attributes');
// $options['attributes'] += ['target' => '_blank'];
// $variables['link']['#url']->setOptions($options);
// }
// }
/**
* Implements hook_theme_suggestions_input_alter().
*/
// function ffw_theme_theme_suggestions_input_alter(&$suggestions, array $variables) {
// $element = $variables['element'];
// if ($element['#type'] === 'search_api_autocomplete' && isset($element['#search_id']) && $element['#search_id'] === 'global_search_solr') {
// $suggestions[] = 'input__textfield__global_autocomplete';
// }
// }
/**
* Implements hook_preprocess_HOOK().
*/
// function ffw_theme_preprocess_node(&$variables) {
// /** @var \Drupal\node\Entity\Node $node */
// $node = $variables['node'];
// if ($node->bundle() === 'homepage') {
// $variables['#attached']['library'][] = 'ffw_theme/homepage';
// }
// }
/**
* Implements hook_theme_suggestions_HOOK_alter() for node.html.twig.
*/
// function ffw_theme_theme_suggestions_node_alter(array &$suggestions, array $variables) {
// // Add template suggestions based on the current view mode.
// $node = $variables['elements']['#node'];
// $view_mode = $variables['elements']['#view_mode'];
// $bundle = $node->bundle();
// $suggestions[] = 'node__' . $bundle;
// $suggestions[] = 'node__' . $bundle . '__' . $view_mode;
// }
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
// function ffw_theme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
// $suggestions[] = 'block__' . $variables['elements']['#plugin_id'];
// $suggestions[] = 'block__' . $variables['elements']['#id'];
// }
/**
* Implements hook_preprocess_HOOK().
*/
// function ffw_theme_preprocess_input(&$variables) {
// // Make autocomplete input in header as 'search' type.
// if (
// $variables["element"]["#type"] === 'search_api_autocomplete' &&
// $variables["element"]["#search_id"] === 'global_search_solr' &&
// $variables["element"]["#additional_data"]["display"] === 'header_search_autocomplete'
// ) {
// $variables["attributes"]["type"] = 'search';
// // Disable autocomplete in Safari.
// // https://bytes.grubhub.com/disabling-safari-autofill-for-a-single-line-address-input-b83137b5b1c7
// $variables["attributes"]["name"] = 'global_search_solr';
// }
// }
/**
* Implements hook_preprocess_media_entity_download_link().
*
* We want to display the media name instead of the filename.
*/
// function ffw_theme_preprocess_media_entity_download_link(&$variables) {
// /** @var \Drupal\media\Entity\Media $media */
// $media = $variables['media_entity'];
// $variables['title'] = $media->label();
// $variables['link']['#title'] = $media->label();
// }
/**
* Implements hook_preprocess_views_view().
*/
// function ffw_theme_preprocess_views_view(&$variables) {
// $view = $variables['view'];
// if ($variables['id'] === 'events_overview' && $variables['display_id'] === 'events_overview') {
// $date_formatter = \Drupal::service('date.formatter');
// $variables['min_date'] = $date_formatter->format(strtotime($view->exposed_raw_input['date_value']['min']), 'events_date_format');
// $variables['max_date'] = $date_formatter->format(strtotime($view->exposed_raw_input['date_value']['max']), 'events_date_format');
// }
// }
/**
* Implements hook_preprocess_block().
*
* Change logo for a specific site.
*/
// function ffw_theme_preprocess_block__system_branding_block(&$variables) {
// // $variables["site_logo"] = '/themes/custom/ffw_theme/logo_canada.svg';
// }