/
field_group.module
757 lines (649 loc) · 24.3 KB
/
field_group.module
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
<?php
/**
* @file
* Allows administrators to attach custom fields to fieldable types.
*/
use Drupal\Component\Utility\Xss;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
require_once __DIR__ . '/includes/helpers.inc';
/**
* Implements hook_theme_registry_alter().
*/
function field_group_theme_registry_alter(&$theme_registry) {
// Inject field_group_build_entity_groups in all entity theming functions.
$entity_info = Drupal::entityManager()->getDefinitions();
$entity_types = array();
foreach ($entity_info as $entity_type_id => $entity_type) {
if ($route_name = $entity_type->get('field_ui_base_route')) {
$entity_types[] = $entity_type_id;
}
}
foreach ($entity_types as $entity_type) {
if (isset($theme_registry[$entity_type])) {
$theme_registry[$entity_type]['preprocess functions'][] = 'field_group_build_entity_groups';
// DS support, make sure it comes after field_group.
if ($key = array_search('ds_preprocess_ds_layout', $theme_registry[$entity_type]['preprocess functions'])) {
unset($theme_registry[$entity_type]['preprocess functions'][$key]);
$theme_registry[$entity_type]['preprocess functions'][] = 'ds_preprocess_ds_layout';
}
}
}
}
/**
* Implements hook_theme().
*/
function field_group_theme() {
return array(
'horizontal_tabs' => array(
'render element' => 'element',
'template' => 'horizontal-tabs',
),
);
}
/**
* Implements hook_form_FORM_ID_alter().
* Using hook_form_field_ui_form_display_overview_form_alter.
*/
function field_group_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) {
$form_state->loadInclude('field_group', 'inc', 'includes/field_ui');
field_group_field_ui_display_form_alter($form, $form_state);
}
/**
* Implements hook_form_FORM_ID_alter().
* Using hook_form_field_ui_display_overview_form_alter.
*/
function field_group_form_entity_view_display_edit_form_alter(&$form, FormStateInterface $form_state) {
$form_state->loadInclude('field_group', 'inc', 'includes/field_ui');
field_group_field_ui_display_form_alter($form, $form_state);
}
/**
* Implements hook_field_info_max_weight().
*/
function field_group_field_info_max_weight($entity_type, $bundle, $context, $context_mode) {
$groups = field_group_info_groups($entity_type, $bundle, $context, $context_mode);
$weights = array();
foreach ($groups as $group) {
$weights[] = $group->weight;
}
return $weights ? max($weights) : NULL;
}
/**
* Implements hook_field_attach_form().
*
* @todo Refactored in field_group_form_alter().
* Remove this function afterwards. Decision has to be made about using
* a pre_render callback or doing the nesting logic immediately in the alter.
*/
function field_group_field_attach_form($entity_type, $entity, &$form, FormStateInterface $form_state, $langcode) {
$form['#attached']['library'][] = 'field_group/field_ui';
field_group_attach_groups($form, 'form', $form_state);
$form['#pre_render'][] = 'field_group_form_pre_render';
}
/**
* Implements hook_form_alter().
*/
function field_group_form_alter(array &$form, FormStateInterface $form_state) {
if ($form_state->getFormObject() instanceof ContentEntityFormInterface) {
$form['#attached']['library'][] = 'field_group/field_ui';
/**
* @var \Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display
*/
$form_display = $form_state->getStorage()['form_display'];
$entity = $form_state->getFormObject()->getEntity();
$context = array(
'entity_type' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
'entity' => $entity,
'context' => 'form',
'display_context' => 'form',
'mode' => $form_display->getMode(),
);
field_group_attach_groups($form, $context);
$form['#pre_render'][] = 'field_group_form_pre_render';
}
}
/**
* Implements hook_entity_display_build_alter().
*/
function field_group_entity_display_build_alter(&$element, $context) {
$context['entity_type'] = $context['display']->getTargetEntityTypeId();
$context['bundle'] = $context['display']->getTargetBundle();
$context['mode'] = $context['display']->getMode();
$context['context'] = 'view';
field_group_attach_groups($element, $context);
}
/**
* Pre render callback for rendering groups.
* @see field_group_field_attach_form
* @param $element Form that is being rendered.
*/
function field_group_form_pre_render(&$element) {
if (empty($element['#field_group_form_pre_render'])) {
$element['#field_group_form_pre_render'] = TRUE;
field_group_build_entity_groups($element, 'form');
}
return $element;
}
/**
* Implements hook_field_group_pre_render().
*
* @param Array $element
* Group beïng rendered.
* @param Object $group
* The Field group info.
* @param $rendering_object
* The entity / form beïng rendered
*/
function field_group_field_group_pre_render(&$element, &$group, &$rendering_object) {
field_group_pre_render_prepare($group);
// Add all field_group format types to the js settings.
$element['#attached']['drupalSettings']['field_group'] = array($group->format_type => $group->mode);
$element['#weight'] = $group->weight;
// Call the pre render function for the format type.
$function = "field_group_pre_render_" . str_replace("-", "_", $group->format_type);
if (function_exists($function)) {
$function($element, $group, $rendering_object);
}
else {
$manager = \Drupal::service('plugin.manager.field_group.formatters');
$plugin = $manager->getInstance(array(
'format_type' => $group->format_type,
'configuration' => array('label' => $group->label, 'settings' => $group->format_settings),
'group' => $group,
));
$plugin->preRender($element);
}
}
/**
* Implements hook_field_group_build_pre_render_alter().
* @param Array $elements by address.
*/
function field_group_field_group_build_pre_render_alter(& $element) {
// Someone is doing a node view, in a node view. Reset content.
if (isset($element['#node']->content) && count($element['#node']->content) > 0) {
$element['#node']->content = array();
}
$display = isset($element['#view_mode']);
$groups = array_keys($element['#fieldgroups']);
// Dish the fieldgroups with no fields for non-forms.
if ($display) {
field_group_remove_empty_display_groups($element, $groups);
}
else {
// Fix the problem on forms with additional settings.
field_group_remove_empty_form_groups('form', $element, $groups, $element['#fieldgroups'], $element['#entity_type']);
}
// Move additional settings to the last multipage pane if configured that way.
// Note that multipages MUST be in the root of the form.
foreach (Element::children($element) as $name) {
if (isset($element[$name]['#type']) && $element[$name]['#type'] == 'multipage' && isset($element['additional_settings'])) {
$parent_group = $element['#fieldgroups'][$name];
$move_additional = isset($parent_group->format_settings['move_additional']) ? $parent_group->format_settings['move_additional'] : 1;
$last_pane = NULL;
foreach (Element::children($element[$name], TRUE) as $pane) {
$last_pane = $pane;
}
$element[$name][$last_pane]['additional_settings'] = $element['additional_settings'];
unset($element['additional_settings']);
}
}
}
/**
* Returns HTML for an element's children fieldsets as horizontal tabs.
*
* @param $variables
* An associative array containing:
* - element: An associative array containing the properties and children of the
* fieldset. Properties used: #children.
*
* @ingroup themeable
*/
function theme_horizontal_tabs($variables) {
$element = $variables['element'];
$output = '<h2 class="visually-hidden">' . (!empty($element['#title']) ? $element['#title'] : t('Horizontal Tabs')) . '</h2>';
$output .= '<div class="horizontal-tabs-panes">' . $element['#children'] . '</div>';
return $output;
}
/**
* Attach groups to the (form) build.
*
* @param Array $element
* The part of the form.
* @param Array $context
* The contextual information.
*/
function field_group_attach_groups(&$element, $context) {
$entity_type = $context['entity_type'];
$bundle = $context['bundle'];
$mode = $context['mode'];
$display_context = $context['context'];
$element['#fieldgroups'] = field_group_info_groups($entity_type, $bundle, $display_context, $mode);
// Create a lookup array.
$group_children = array();
foreach ($element['#fieldgroups'] as $group_name => $group) {
foreach ($group->children as $child) {
$group_children[$child] = $group_name;
}
}
$element['#group_children'] = $group_children;
$element['#entity_type'] = $entity_type;
}
/**
* Preprocess/ Pre-render callback.
*
* @see field_group_form_pre_render()
* @see field_group_theme_registry_alter
* @see field_group_fields_nest()
* @param $vars preprocess vars or form element
* @param $context The display context (form or view)
* @return $element Array with re-arranged fields in groups.
*/
function field_group_build_entity_groups(&$vars, $context = 'view') {
if ($context == 'form') {
$element = &$vars;
$nest_vars = NULL;
}
else {
$element = &$vars['elements'];
$nest_vars = &$vars;
}
// No groups on the entity.
if (empty($element['#fieldgroups'])) {
return $element;
}
// Nest the fields in the corresponding field groups.
field_group_fields_nest($element, $nest_vars);
// Allow others to alter the pre_rendered build.
Drupal::moduleHandler()->alter('field_group_build_pre_render', $element);
// Return the element on forms.
if ($context == 'form') {
return $element;
}
// No groups on the entity. Prerender removed empty field groups.
if (empty($element['#fieldgroups'])) {
return $element;
}
// Put groups inside content if we are rendering an entity_view.
foreach ($element['#fieldgroups'] as $group) {
if (!empty($element[$group->group_name]) && $context != 'user_profile') {
$vars['content'][$group->group_name] = $element[$group->group_name];
}
elseif (!empty($element[$group->group_name])) {
$vars['user_profile'][$group->group_name] = $element[$group->group_name];
}
}
}
/**
* Recursive function to nest fields in the field groups.
*
* This function will take out all the elements in the form and
* place them in the correct container element, a fieldgroup.
* The current group element in the loop is passed recursively so we can
* stash fields and groups in it while we go deeper in the array.
* @param Array $element
* The current element to analyse for grouping.
* @param Array $vars
* Rendering vars from the entity being viewed.
*/
function field_group_fields_nest(&$element, &$vars = NULL) {
// Create all groups and keep a flat list of references to these groups.
$group_references = array();
foreach ($element['#fieldgroups'] as $group_name => $group) {
// Construct own weight, as some fields (for example preprocess fields) don't have weight set.
$element[$group_name] = array();
$group_references[$group_name] = &$element[$group_name];
}
// Loop through all form children looking for those that are supposed to be
// in groups, and insert placeholder element for the new group field in the
// correct location within the form structure.
$element_clone = array();
foreach (Element::children($element) as $child_name) {
$element_clone[$child_name] = $element[$child_name];
// If this element is in a group, create the placeholder element.
if (isset($element['#group_children'][$child_name])) {
$element_clone[$element['#group_children'][$child_name]] = array();
}
}
$element = array_merge($element_clone, $element);
// Move all children to their parents. Use the flat list of references for
// direct access as we don't know where in the root_element hierarchy the
// parent currently is situated.
foreach ($element['#group_children'] as $child_name => $parent_name) {
// Entity being viewed
if ($vars) {
// If not a group, check vars['content'] for empty field.
if (!isset($element['#fieldgroups'][$child_name]) && isset($vars['content'][$child_name])) {
$group_references[$parent_name][$child_name] = $vars['content'][$child_name];
unset($vars['content'][$child_name]);
}
elseif (!isset($element['#fieldgroups'][$child_name]) && isset($vars['user_profile'][$child_name])) {
$group_references[$parent_name][$child_name] = $vars['user_profile'][$child_name];
unset($vars['user_profile'][$child_name]);
}
// If this is a group, we have to use a reference to keep the reference
// list intact (but if it is a field we don't mind).
else {
$group_references[$parent_name][$child_name] = &$element[$child_name];
unset($element[$child_name]);
}
}
// Form being viewed
else {
// Block denied fields (#access) before they are put in groups.
// Fields (not groups) that don't have children (like field_permissions) are removed
// in field_group_field_group_build_pre_render_alter.
if (isset($element[$child_name]) && (!isset($element[$child_name]['#access']) || $element[$child_name]['#access'])) {
// If this is a group, we have to use a reference to keep the reference
// list intact (but if it is a field we don't mind).
$group_references[$parent_name][$child_name] = &$element[$child_name];
$group_references[$parent_name]['#weight'] = $element['#fieldgroups'][$parent_name]->weight;
}
// The child has been copied to its parent: remove it from the root element.
unset($element[$child_name]);
}
}
// Bring extra element wrappers to achieve a grouping of fields.
// This will mainly be prefix and suffix altering.
foreach ($element['#fieldgroups'] as $group_name => $group) {
field_group_pre_render($group_references[$group_name], $group, $element);
}
}
/**
* Function to pre render the field group element.
*
* @see field_group_fields_nest()
*
* @param $element
* Render array of group element that needs to be created.
* @param $group
* Object with the group information.
* @param $rendering_object
* The entity / form beïng rendered.
*/
function field_group_pre_render(& $element, $group, & $rendering_object) {
// Only run the pre_render function if the group has elements.
// $group->group_name
if ($element == array()) {
return;
}
// Let modules define their wrapping element.
// Note that the group element has no properties, only elements.
foreach (Drupal::moduleHandler()->getImplementations('field_group_pre_render') as $module) {
// The intention here is to have the opportunity to alter the
// elements, as defined in hook_field_group_formatter_info.
// Note, implement $element by reference!
$function = $module . '_field_group_pre_render';
$function($element, $group, $rendering_object);
}
// Allow others to alter the pre_render.
Drupal::moduleHandler()->alter('field_group_pre_render', $element, $group, $rendering_object);
}
/**
* Helper function to prepare basic variables needed for most formatters.
*
* Called in field_group_field_group_pre_render(), but can also be called in
* other implementations of hook_field_group_pre_render().
*/
function field_group_pre_render_prepare(&$group) {
$classes = _field_group_get_html_classes($group);
$group->classes = implode(' ', $classes->required);
$group->description = !empty($group->format_settings['instance_settings']['description']) ? Xss::filterAdmin(t($group->format_settings['instance_settings']['description'])) : '';
}
/**
* Saves a group definition.
* This function is called by ctools export when calls are made
* through ctools_export_crud_save().
*
* @param $group
* A group definition.
*/
function field_group_group_save(&$group) {
if ($group->context == 'form') {
$display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
if ($group->context == 'view') {
$display = EntityViewDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
/**
* @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface
*/
if (isset($display)) {
$data = (array) $group;
unset($data['group_name'], $data['entity_type'], $data['bundle'], $data['mode'], $data['form'], $data['context']);
$display->setThirdPartySetting('field_group', $group->group_name, $data);
$display->save();
}
}
/**
* Delete a field group.
*
* @param $group
* A group definition.
*/
function field_group_group_delete($group) {
if ($group->context == 'form') {
$display = EntityFormDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
if ($group->context == 'view') {
$display = EntityViewDisplay::load($group->entity_type . '.' . $group->bundle . '.' . $group->mode);
}
/**
* @var $display \Drupal\Core\Entity\Display\EntityDisplayInterface
*/
if (isset($display)) {
$display->unsetThirdPartySetting('field_group', $group->group_name);
$display->save();
}
Drupal::moduleHandler()->invokeAll('field_group_delete_field_group', array($group));
}
/**
* Get all groups.
*
* @param $entity_type
* The name of the entity.
* @param $bundle
* The name of the bundle.
* @param $context
* The context of the view mode (form or view)
* @param $mode
* The view mode.
*/
function field_group_info_groups($entity_type, $bundle, $context, $mode) {
if ($context == 'form') {
$display = EntityFormDisplay::load($entity_type . '.' . $bundle . '.' . $mode);
if (!$display) {
return array();
}
$data = $display->getThirdPartySettings('field_group');
}
if ($context == 'view') {
$display = EntityViewDisplay::load($entity_type . '.' . $bundle . '.' . $mode);
if (!$display) {
return array();
}
$data = $display->getThirdPartySettings('field_group');
}
$groups = array();
if (isset($data)) {
foreach ($data as $group_name => $definition) {
$definition += array(
'group_name' => $group_name,
'entity_type' => $entity_type,
'bundle' => $bundle,
'context' => $context,
'mode' => $mode,
);
$groups[$group_name] = (object) $definition;
}
}
return $groups;
}
/**
* Loads a group definition.
*
* @param $group_name
* The name of the group.
* @param $entity_type
* The name of the entity.
* @param $bundle_name
* The name of the bundle.
* @param $context
* The context of the view mode (form or view)
* @param $mode
* The view mode to load.
*/
function field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode) {
$groups = field_group_info_groups($entity_type, $bundle, $context, $mode);
if (isset($groups[$group_name])) {
return $groups[$group_name];
}
}
/**
* Checks if a field_group exists in required context.
*
* @param String $group_name
* The name of the group.
* @param String $entity_type
* The name of the entity.
* @param String $bundle
* The bundle for the entity.
* @param $context
* The context of the view mode (form or view)
* @param String $mode
* The view mode context the group will be rendered.
*/
function field_group_exists($group_name, $entity_type, $bundle, $context, $mode) {
return (bool) field_group_load_field_group($group_name, $entity_type, $bundle, $context, $mode);
}
/**
* Remove empty groups on forms.
*
* @param String $parent_name
* The name of the element.
* @param array $element
* The element to check the empty state.
* @param array $groups
* Array of group objects.
*/
function field_group_remove_empty_form_groups($name, & $element, $groups, &$form_groups, $entity) {
$exceptions = array('user__account', 'comment__author');
$children = Element::children($element);
$hasChildren = FALSE;
if (count($children)) {
foreach ($children as $childname) {
if (in_array($childname, $groups)) {
field_group_remove_empty_form_groups($childname, $element[$childname], $groups, $form_groups, $entity);
}
$exception = $entity . '__' . $childname;
$hasChildren = $hasChildren ? TRUE : (isset($element[$childname]['#type']) || isset($element[$childname]['#markup']) || in_array($exception, $exceptions));
}
}
if (!$hasChildren) {
// Remove empty elements from the #fieldgroups.
if (empty($element) && isset($form_groups[$name]) && !is_array($form_groups[$name])) {
foreach ($form_groups as $group_name => $group) {
if (isset($group->children)) {
$group_children = array_flip($group->children);
if (isset($group_children[$name])) {
unset($form_groups[$group_name]->children[$group_children[$name]]);
}
}
}
}
$element['#access'] = FALSE;
}
}
/**
* Remove empty groups on entity display.
* @param array $element
* The element to check the empty state.
* @param array $groups
* Array of group objects.
*/
function field_group_remove_empty_display_groups(& $element, $groups) {
$empty_child = TRUE;
$empty_group = TRUE;
// Loop through the children for current element.
foreach (Element::children($element) as $name) {
// Descend if the child is a group.
if (in_array($name, $groups)) {
$empty_child = field_group_remove_empty_display_groups($element[$name], $groups);
if (!$empty_child) {
$empty_group = FALSE;
}
}
// Child is a field, the element is not empty and access is set to true (or empty).
elseif (!empty($element[$name])) {
$has_access = !isset($element[$name]['#access']) || $element[$name]['#access'];
$has_markup = isset($element[$name]['#markup']);
$has_items = isset($element[$name][0]);
if ($has_access && ($has_markup || $has_items)) {
$empty_group = FALSE;
}
}
}
// Reset an empty group.
if ($empty_group) {
$element = NULL;
}
return $empty_group;
}
/**
* Implements field_group_pre_render_<format-type>.
* Format type: Div.
*
* @param $element
* The field group render array.
* @param $group
* The Field group object prepared for pre_render.
* @param $rendering_object
* The entity / form beïng rendered.
*/
function field_group_pre_render_div(&$element, $group, &$rendering_object) {
$show_label = isset($group->format_settings['show_label']) ? $group->format_settings['show_label'] : 0;
$label_element = isset($group->format_settings['label_element']) ? $group->format_settings['label_element'] : 'h2';
$effect = isset($group->format_settings['effect']) ? $group->format_settings['effect'] : 'none';
$element['#type'] = 'markup';
$id = isset($element['#id']) ? ' id="' . $element['#id'] . '"' : '';
if ($group->format_settings['formatter'] != 'open') {
$element['#prefix'] = '<div' . $id . ' class="' . $group->classes . '">
<' . $label_element . '><span class="field-group-format-toggler">' . SafeMarkup::checkPlain(t($group->label)) . '</span></' . $label_element . '>
<div class="field-group-format-wrapper" style="display: ' . (!empty($group->collapsed) ? 'none' : 'block') . ';">';
$element['#suffix'] = '</div></div>';
$element['#attached']['library'][] = 'field_group/formatter.div';
if ($effect == 'blind') {
$element['#attached']['library'][] = 'core/jquery.ui.effects.blind';
}
}
else {
$class_attribute = !empty($group->classes) ? ' class="' . $group->classes . '"' : '';
$element['#prefix'] = '<div' . $id . $class_attribute . '>';
if ($show_label) {
$element['#prefix'] .= '<' . $label_element . '><span>' . SafeMarkup::checkPlain(t($group->label)) . '</span></' . $label_element . '>';
}
$element['#suffix'] = '</div>';
}
if (!empty($group->description)) {
$element['#prefix'] .= '<div class="description">' . $group->description . '</div>';
}
}
/**
* Prepares variables for horizontal tabs templates.
*
* Default template: horizontal-tabs.html.twig.
*
* @param array $variables
* An associative array containing:
* - element: An associative array containing the properties and children of
* the details element. Properties used: #children.
*
*/
function template_preprocess_horizontal_tabs(&$variables) {
$element = $variables['element'];
$variables['children'] = (!empty($element['#children'])) ? $element['#children'] : '';
}