function claro_views_ui_display_tab_alter in Drupal 8
Same name and namespace in other branches
- 9 core/themes/claro/claro.theme \claro_views_ui_display_tab_alter()
Implements hook_views_ui_display_tab_alter().
File
- core/
themes/ claro/ claro.theme, line 562 - Functions to support theming in the Claro theme.
Code
function claro_views_ui_display_tab_alter(&$element) {
// We process the dropbutton-like element on views edit form's
// display settings top section.
//
// That element should be a regular Dropbutton.
//
// After that the reported issue is fixed and the element is rendered with
// the Dropbutton type, we just have to set it's '#dropbutton_type' to
// 'extrasmall'.
//
// @todo: revisit after https://www.drupal.org/node/3057577 is fixed.
$dummy_dropbutton =& $element['details']['top']['actions'];
if ($dummy_dropbutton) {
$child_keys = Element::children($dummy_dropbutton);
$prefix_regex = '/(<.*class\\s*= *["\']?)([^"\']*)(.*)/i';
$child_count = 0;
foreach ($child_keys as $key) {
if (in_array($key, [
'prefix',
'suffix',
])) {
continue;
}
$nested_child_keys = Element::children($dummy_dropbutton[$key], TRUE);
if (!empty($nested_child_keys)) {
foreach ($nested_child_keys as $nested_key) {
$child_count++;
$prefix = $dummy_dropbutton[$key][$nested_key]['#prefix'];
$dummy_dropbutton[$key][$nested_key]['#prefix'] = preg_replace($prefix_regex, '$1$2 dropbutton__item dropbutton__item--extrasmall$3', $prefix);
}
}
else {
$child_count++;
$prefix = $dummy_dropbutton[$key]['#prefix'];
$dummy_dropbutton[$key]['#prefix'] = preg_replace($prefix_regex, '$1$2 dropbutton__item dropbutton__item--extrasmall$3', $prefix);
}
}
if (!empty($dummy_dropbutton['prefix']) && !empty($dummy_dropbutton['prefix']['#markup'])) {
$classes = 'dropbutton--extrasmall ';
$classes .= $child_count > 1 ? 'dropbutton--multiple' : 'dropbutton--single';
$prefix = $dummy_dropbutton['prefix']['#markup'];
$dummy_dropbutton['prefix']['#markup'] = preg_replace($prefix_regex, '$1$2 ' . $classes . '$3', $prefix);
}
}
}