function ViewsHooks::viewsUiDisplayTopAlter

Same name and namespace in other branches
  1. 11.x core/themes/admin/src/Hook/ViewsHooks.php \Drupal\admin\Hook\ViewsHooks::viewsUiDisplayTopAlter()

Implements hook_views_ui_display_top_alter().

Attributes

#[Hook('views_ui_display_top_alter')]

File

core/themes/admin/src/Hook/ViewsHooks.php, line 78

Class

ViewsHooks
Provides views related hook implementations.

Namespace

Drupal\admin\Hook

Code

public function viewsUiDisplayTopAlter(array &$element) : void {
  // @todo Remove this after https://www.drupal.org/node/3051605 has been
  //   solved.
  $element['tabs']['#prefix'] = preg_replace('/(class="(.+\\s)?)tabs(\\s.+"|")/', '$1views-tabs$3', $element['tabs']['#prefix']);
  $element['tabs']['#prefix'] = preg_replace('/(class="(.+\\s)?)secondary(\\s.+"|")/', '$1views-tabs--secondary$3', $element['tabs']['#prefix']);
  foreach (Element::children($element['tabs']) as $tab) {
    $element['tabs'][$tab]['#theme'] = 'menu_local_task__views_ui';
  }
  // Change top extra actions to use the small dropbutton variant.
  // @todo Revisit after https://www.drupal.org/node/3057581 is added.
  if (!empty($element['extra_actions'])) {
    $element['extra_actions']['#dropbutton_type'] = 'small';
  }
  // Add a class to each item in the add display dropdown so they can be
  // styled with a single selector.
  if (isset($element['add_display'])) {
    foreach ($element['add_display'] as &$display_item) {
      if (isset($display_item['#type']) && in_array($display_item['#type'], [
        'submit',
        'button',
      ], TRUE)) {
        $display_item['#attributes']['class'][] = 'views-tabs__action-list-button';
      }
    }
    unset($display_item);
  }
  // Rearrange top bar contents so floats aren't necessary for positioning.
  if (isset($element['extra_actions'], $element['add_display'])) {
    $element['extra_actions']['#weight'] = 10;
    $element['extra_actions']['#theme_wrappers'] = [
      'container' => [
        '#attributes' => [
          'class' => [
            'views-display-top__extra-actions-wrapper',
          ],
        ],
      ],
    ];
    $element['#attributes']['class'] = array_diff($element['#attributes']['class'], [
      'clearfix',
    ]);
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.