-
Notifications
You must be signed in to change notification settings - Fork 2
/
lark.theme
253 lines (224 loc) · 9.1 KB
/
lark.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
245
246
247
248
249
250
251
252
253
<?php
use Drupal\Core\Form\FormStateInterface;
function lark_preprocess_page(&$variables) {
$shortcuts = shortcut_renderable_links();
$variables['shortcuts'] = $shortcuts;
}
/**
* Implements hook_form_system_theme_settings_alter().
*/
function lark_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id = NULL) {
// Work around for core bug affecting admin themes. See issue #943212.
if (isset($form_id)) {
return;
}
$form['lark_color'] = array(
'#type' => 'textfield',
'#title' => t('Primary color'),
'#default_value' => theme_get_setting('lark_color'),
'#description' => t('Provide a hexadecimal value to use as the theme\'s primary color.'),
);
}
/**
* Implements hook_form_alter().
*
* @param $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $form_id
*/
function lark_forms_form_alter(&$form, FormStateInterface $form_state, $form_id) {
lark_forms_attach_form_id($form, $form_id);
if ($form_id === 'views_exposed_form') {
$display_id = str_replace('views-exposed-form-', '', $form['#id']);
$display_id = str_replace('-', '_', $display_id);
lark_forms_attach_views_display_id($form, $display_id);
}
}
/**
* Implements hook_theme_suggestions_form_alter().
*
* @param array $suggestions
* @param array $variables
*/
function lark_theme_suggestions_form_alter(array &$suggestions, array $variables) {
// Add form suggestions for form--form-id.html.twig.
$element = $variables['element'];
$suggestions[] = 'form__' . str_replace('-', '_', $element['#form_id']);
$suggestions[] = 'form__' . str_replace('-', '_', $element['#form_id']) . '__' . str_replace('-', '_', $element['#id']);
}
/**
* Implements hook_theme_suggestions_container_alter().
*
* @param array $suggestions
* @param array $variables
*/
function lark_theme_suggestions_container_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
if (isset($element['#type']) && $element['#type'] != 'container') {
$suggestions[] = 'container__' . str_replace('-', '_', $element['#type']);
if (isset($element['#attributes']['data-twig-suggestion'])) {
$suggestions[] = 'container__' . str_replace('-', '_', $element['#type']) . '__' . str_replace('-', '_', $element['#attributes']['data-twig-suggestion']);
}
}
if(isset($element['#id'])) {
$suggestions[] = 'container__' . str_replace('-', '_', $element['#id']);
}
if (isset($element['#type']) && $element['#type'] == 'container' && isset($element['children']['#type'])) {
$suggestions[] = 'container__' . str_replace('-', '_', $element['children']['#type']);
}
if (isset($variables['element']['#type']) && isset($element['#name'])) {
$suggestions[] = 'container__' . str_replace('-', '_', $element['#type']) . '__' . str_replace('-', '_', $element['#name']);
}
if (isset($variables['element']['#type']) && isset($element['#name']) && isset($element['#display_id'])) {
$suggestions[] = 'container__' . str_replace('-', '_', $element['#type']) . '__' . str_replace('-', '_', $element['#name']) . '__' . str_replace('-', '_', $element['#display_id']);
}
}
/**
* Implements hook_theme_suggestions_input_alter().
*
* @param $suggestions
* @param array $variables
*/
function lark_theme_suggestions_input_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
if (isset($element['#attributes']['data-twig-suggestion'])) {
$suggestion_suffix = str_replace(['-'], '_', $element['#attributes']['data-twig-suggestion']);
$suggestions[] = 'input__' . str_replace('-', '_', $element['#type']) . '__' . $suggestion_suffix;
}
}
/**
* Implements hook_theme_suggestions_select_alter().
*
* @param array $suggestions
* @param array $variables
*/
function lark_theme_suggestions_select_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
if (isset($element['#attributes']['data-twig-suggestion'])) {
$suggestions[] = 'select__' . str_replace('-', '_', $element['#attributes']['data-twig-suggestion']);
}
}
/**
* Implements hook_form_alter().
*
* @param $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
* @param $form_id
*/
function lark_form_alter(&$form, FormStateInterface $form_state, $form_id) {
foreach (\Drupal\Core\Render\Element::children($form) as $key) {
$form[$key]['#attributes']['data-twig-suggestion'] = $form['#id'];
}
$form['actions']['submit']['#attributes']['data-twig-suggestion'] = $form['#id'];
// Valid admin path for nodes and media content.
$isAdminContentPath = substr($form['#action'], 0, 14) == '/admin/content' ? True : False;
// Change Operations for Action in admin content form.
if ($isAdminContentPath and isset($form['output'][0]['#view']->field['operations'])) {
if ($form['output'][0]['#view']->field['operations']->options['label'] == 'Operations'){
$form['output'][0]['#view']->field['operations']->options['label'] = 'Action';
}
}
}
/**
* Implements hook_theme_suggestions_form_element().
*
* @param array $suggestions
* @param array $variables
*/
function lark_theme_suggestions_form_element_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
if (!empty($element['#type'])) {
$suggestions[] = 'form_element__type__' . str_replace('-', '_', $element['#type']);
if (isset($element['#attributes']['data-twig-suggestion'])) {
$suggestions[] = 'form_element__type__' . str_replace('-', '_', $element['#type']) . '__' . str_replace('-', '_', $element['#attributes']['data-twig-suggestion']);
}
}
if (isset($element['#form_id'])) {
$suggestions[] = 'form_element__form_id__' . str_replace('-', '_', $element['#form_id']);
if (!empty($element['#type'])) {
$suggestions[] = 'form_element__' . str_replace('-', '_', $element['#form_id']) . '__' . str_replace('-', '_', $element['#type']);
}
}
if (isset($element['#views_display_id'])) {
$suggestions[] = 'form_element__' . str_replace('-', '_', $element['#form_id']) . '__' . str_replace('-', '_', $element['#views_display_id']);
if (!empty($element['#type'])) {
$suggestions[] = 'form_element__' . str_replace('-', '_', $element['#form_id']) . '__' . str_replace('-', '_', $element['#views_display_id']) . '__' . str_replace('-', '_', $element['#type']);
}
}
}
/**
* Implements hook_theme_suggestions_form_element_label().
*
* @param array $suggestions
* @param array $variables
*/
function lark_theme_suggestions_form_element_label_alter(array &$suggestions, array $variables) {
$element = $variables['element'];
if (isset($element['#form_element_type'])) {
$suggestions[] = 'form_element_label__type__' . str_replace('-', '_', $element['#form_element_type']);
}
if (isset($element['#form_id'])) {
$suggestions[] = 'form_element_label__form-id__' . str_replace('-', '_', $element['#form_id']);
}
if (isset($element['#form_element_type']) && isset($element['#form_id'])) {
$suggestions[] = 'form_element_label__' . str_replace('-', '_', $element['#form_id']) . '__' . str_replace('-', '_', $element['#form_element_type']);
}
if (isset($element['#views_display_id'])) {
$suggestions[] = 'form_element_label__views_exposed_form__' . str_replace('-', '_', $element['#views_display_id']);
}
if (isset($element['#views_display_id']) && isset($element['#form_id'])) {
$suggestions[] = 'form_element_label__views_exposed_form__' . str_replace('-', '_', $element['#views_display_id']) . '__' . str_replace('-', '_', $element['#form_element_type']);
}
}
/**
* Implements hook_preprocess_form_element().
*/
function lark_preprocess_form_element(array &$variables) {
$element = $variables['element'];
if (!isset($variables['label'])) {
return;
}
if (isset($element['#form_id'])) {
$variables['label']['#form_id'] = str_replace('-', '_', $element['#form_id']);
}
if (isset($element['#type'])) {
$variables['label']['#form_element_type'] = str_replace('-', '_', $element['#type']);
}
if (isset($element['#views_display_id'])) {
$variables['label']['#views_display_id'] = str_replace('-', '_', $element['#views_display_id']);
}
}
/**
* Attaches form id to all form elements.
*
* @param $form
* The form or form element which children should have form id attached.
* @param $form_id
* The form id attached to form elements.
*
*/
function lark_forms_attach_form_id(&$form, $form_id) {
foreach (Element::children($form) as $child) {
if (!isset($form[$child]['#form_id'])) {
$form[$child]['#form_id'] = $form_id;
}
lark_forms_attach_form_id($form[$child], $form_id);
}
}
/**
* Attaches views display id to all form elements
*
* @param $form
* The form or form element which children should have views display id attached.
* @param $views_display_id
* The views display id attached to form elements.
*
*/
function lark_forms_attach_views_display_id(&$form, $views_display_id) {
foreach (Element::children($form) as $child) {
if (!isset($form[$child]['#views_display_id'])) {
$form[$child]['#views_display_id'] = $views_display_id;
}
lark_forms_attach_views_display_id($form[$child], $views_display_id);
}
}