-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkramis.theme
401 lines (333 loc) · 11.2 KB
/
kramis.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
/**
* @file
* Functions to support theming in the kramis theme.
*/
// Ads the sidbar entity form layout to other entities besides node.
function _kramis_entity_form_col(&$form, &$form_state, $form_id) {
// Use the node edit form template.
$form['#theme'][] = 'node_edit_form';
// Use the node form layout library.
$form['#attached']['library'] = ['node/drupal.node'];
// Create the advanced element if it doesn't exist.
if (!isset($form['advanced'])) {
$form['advanced'] = [
'#type' => 'container',
'#weight' => 99,
];
}
else {
// Make 'advanced' a container instead of vertical_tabs.
$form['advanced']['#type'] = 'container';
}
// Add the style class to tell the admin theme how to style it.
$form['advanced']['#attributes']['class'][] = 'entity-meta';
if (!isset($form['meta'])) {
$form['meta'] = [
'#type' => 'container',
'#group' => 'advanced',
'#weight' => -10,
'#title' => 'Status',
'#attributes' => ['class' => ['entity-meta__header']],
'#tree' => TRUE,
];
}
}
function kramis_gutenberg_node_type_enabled($node){
$config = \Drupal::service('config.factory')->getEditable('gutenberg.settings');
return $config->get($node->bundle() . '_enable_full');
}
/**
* Alters an entity edit form layout.
*
* Move the published checkbox to the meta sidebar.
* Duplicate the submit button and put it in the meta sidebar.
*/
function _kramis_move_entity_form_fields(&$form, &$form_state, $form_id) {
// Move detail elements into 'advanced'.
//$form['detail_element_you_want_to_move']['#group'] = 'advanced';
// move published to meta box.
if (isset($form['status'])) {
$form['status']['#group'] = 'meta';
$form['status']['#weight'] = 1;
}
// Duplicate the submit button in to the metabox.
if (isset($form['actions']['submit'])) {
$form['sidebar_actions'] = [
'#type' => 'container',
'#group' => 'meta',
'#weight' => -100,
'#attributes' => ['class' => ['sidebar-actions', 'form-actions']],
'submit' => $form['actions']['submit'],
];
}
// Use the formatted name in the author meta.
if (isset($form['meta']['author']['#markup'])) {
$entity = $form_state->getFormObject()->getEntity();
$form['meta']['author']['#markup'] = $entity->getOwner()->getDisplayName();
}
// Move the lead image if there is one.
if (isset($form['field_lead_image'])) {
// Move the lead image field into the meta box.
$form['field_lead_image']['#group'] = 'meta';
//$form['field_lead_image']['widget'][0]['#weight'] = 500;
}
if (isset($form['field_cover'])) {
// Move the lead image field into the meta box.
$form['field_cover']['#group'] = 'meta';
//$form['field_lead_image']['widget'][0]['#weight'] = 500;
}
/* if(isset($form['field_cover_image'])){
// Move the lead image field into the meta box.
$form['field_cover_image']['#group'] = 'meta';
//$form['field_lead_image']['widget'][0]['#weight'] = 500;
}*/
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Product License entities.
*/
function kramis_form_achievement_form_alter(&$form, &$form_state, $form_id) {
//_kramis_entity_form_col($form, $form_state, $form_id);
//_kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Product License entities.
*/
function kramis_form_message_form_alter(&$form, &$form_state, $form_id) {
_kramis_entity_form_col($form, $form_state, $form_id);
_kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Product License entities.
*/
function kramis_form_product_license_form_alter(&$form, &$form_state, $form_id) {
//_kramis_entity_form_col($form, $form_state, $form_id);
//_kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Group entities.
*/
function kramis_form_group_form_alter(&$form, &$form_state, $form_id) {
_kramis_entity_form_col($form, $form_state, $form_id);
_kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Commerce Product entities.
*/
function kramis_form_commerce_product_form_alter(&$form, &$form_state, $form_id) {
_kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Node entities.
*/
function kramis_form_node_form_alter(&$form, &$form_state, $form_id) {
$node = $form_state->getFormObject()->getEntity();
if(!kramis_gutenberg_node_type_enabled($node)) {
//$node = $form_state->getFormObject()->getEntity();
//if($node->bundle() != 'contest') {
_kramis_entity_form_col($form, $form_state, $form_id);
_kramis_move_entity_form_fields($form, $form_state, $form_id);
//}
// articles not using gutenberg.
if($node->bundle() == 'article'){
$form['moderation_state']['#group'] = 'meta';
$form['revision_information']['#group'] = 'advanced';
$form['revision_information']['#type'] = 'details';
$form['revision_information']['#open'] = FALSE;
$form['revision_log']['#group'] = 'revision_information';
$form['field_publish_on']['#group'] = 'meta';
$form['comment']['widget'][0]['#weight'] = 300;
}
} else {
// Gurenberg sidebar.
// move published to meta box.
if (isset($form['status'])) {
$form['status']['#group'] = 'meta';
$form['status']['#weight'] = 1;
}
$form['moderation_state']['#group'] = 'meta';
$form['revision_information']['#group'] = 'advanced';
$form['revision_information']['#type'] = 'details';
$form['revision_information']['#open'] = FALSE;
$form['revision_log']['#group'] = 'revision_information';
$form['field_publish_on']['#group'] = 'meta';
$form['comment']['widget'][0]['#weight'] = 300;
// Use the formatted name in the author meta.
if (isset($form['meta']['author']['#markup'])) {
$entity = $form_state->getFormObject()->getEntity();
$form['meta']['author']['#markup'] = $entity->getOwner()->getDisplayName();
}
}
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Node entities.
*/
function kramis_form_block_content_form_alter(&$form, &$form_state, $form_id) {
_kramis_entity_form_col($form, $form_state, $form_id);
_kramis_move_entity_form_fields($form, $form_state, $form_id);
$form['template_suggestion']['#type'] = 'details';
$form['template_suggestion']['#title'] = t('Template Suggestions');
$form['template_suggestion']['#open'] = TRUE;
$form['template_suggestion']['#group'] = 'advanced';
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Node entities.
*/
function kramis_form_taxonomy_term_form_alter(&$form, &$form_state, $form_id) {
_kramis_entity_form_col($form, $form_state, $form_id);
_kramis_move_entity_form_fields($form, $form_state, $form_id);
// Move relations fieldset to side col.
if (isset($form['relations'])) {
$form['relations']['#group'] = 'advanced';
}
// Weap Url in fieldset and move to side col.
if (isset($form['path'])) {
$form['path_wrapper'] = [
'#type' => 'details',
'#title' => t('URL Path'),
'#group' => 'advanced',
];
$form['path_wrapper']['path'] = $form['path'];
unset($form['path']);
}
}
/**
* Implements hook_form_BASE_FORM_alter().
*
* Media entities.
*/
function kramis_form_media_form_alter(&$form, &$form_state, $form_id) {
// _kramis_entity_form_col($form, $form_state, $form_id);
// _kramis_move_entity_form_fields($form, $form_state, $form_id);
}
/**
* Implements hook_preprocess_HOOK() for html.html.twig.
*/
function kramis_preprocess_html(array &$variables) {
/* Add class to html tag */
//$variables['html_attributes']->addClass('no-js');
// Don't display the site name twice on the front page (and potentially others)
/*if (isset($variables['head_title_array']['title']) && isset($variables['head_title_array']['name']) && ($variables['head_title_array']['title'] == $variables['head_title_array']['name'])) {
$variables['head_title'] = $variables['head_title_array']['name'];
}*/
}
/**
* Implements hook_page_attachments_alter().
*/
function kramis_page_attachments_alter(array &$page) {
// Tell IE to use latest rendering engine (not to use compatibility mode).
/*$ie_edge = [
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => [
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge',
],
];
$page['#attached']['html_head'][] = [$ie_edge, 'ie_edge'];*/
}
/**
* Implements hook_preprocess_page() for page.html.twig.
*/
function kramis_preprocess_page(array &$variables) {
}
/**
* Implements hook_theme_suggestions_page_alter().
*/
function kramis_theme_suggestions_page_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_theme_suggestions_node_alter().
*/
function kramis_theme_suggestions_node_alter(array &$suggestions, array $variables) {
/*$node = $variables['elements']['#node'];
if ($variables['elements']['#view_mode'] == "full") {
}*/
}
/**
* Implements hook_preprocess_HOOK() for Block document templates.
*/
function kramis_preprocess_block(array &$variables) {
}
/**
* Implements hook_theme_suggestions_field_alter().
*/
function kramis_theme_suggestions_field_alter(array &$suggestions, array $variables) {
/*$element = $variables['element'];
$suggestions[] = 'field__' . $element['#view_mode'];
$suggestions[] = 'field__' . $element['#view_mode'] . '__' . $element['#field_name'];*/
}
/**
* Implements hook_theme_suggestions_field_alter().
*/
function kramis_theme_suggestions_fieldset_alter(array &$suggestions, array $variables) {
/*$element = $variables['element'];
if (isset($element['#attributes']['class']) && in_array('form-composite', $element['#attributes']['class'])) {
$suggestions[] = 'fieldset__form_composite';
}*/
}
/**
* Implements hook_preprocess_node().
*/
function kramis_preprocess_node(array &$variables) {
// Default to turning off byline/submitted.
$variables['display_submitted'] = FALSE;
}
/**
* Implements hook_theme_suggestions_views_view_alter().
*/
function kramis_theme_suggestions_views_view_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_preprocess_form().
*/
function kramis_preprocess_form(array &$variables) {
//$variables['attributes']['novalidate'] = 'novalidate';
}
/**
* Implements hook_preprocess_select().
*/
function kramis_preprocess_select(array &$variables) {
//$variables['attributes']['class'][] = 'select-chosen';
}
/**
* Implements hook_preprocess_field().
*/
function kramis_preprocess_field(array &$variables, $hook) {
/*switch ($variables['element']['#field_name']) {
}*/
}
/**
* Implements hook_preprocess_details().
*/
function kramis_preprocess_details(array &$variables) {
/*$variables['attributes']['class'][] = 'details';
$variables['summary_attributes']['class'] = 'summary';*/
}
/**
* Implements hook_theme_suggestions_details_alter().
*/
function kramis_theme_suggestions_details_alter(array &$suggestions, array $variables) {
}
/**
* Implements hook_preprocess_menu_local_task().
*/
function kramis_preprocess_menu_local_task(array &$variables) {
//$variables['element']['#link']['url']->setOption('attributes', ['class'=>'rounded']);
}