function ViewFormBase::getDisplayTabs

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewFormBase.php \Drupal\views_ui\ViewFormBase::getDisplayTabs()
  2. 10 core/modules/views_ui/src/ViewFormBase.php \Drupal\views_ui\ViewFormBase::getDisplayTabs()
  3. 11.x core/modules/views_ui/src/ViewFormBase.php \Drupal\views_ui\ViewFormBase::getDisplayTabs()

Adds tabs for navigating across Displays when editing a View.

This function can be called from hook_menu_local_tasks_alter() to implement these tabs as secondary local tasks, or it can be called from elsewhere if having them as secondary local tasks isn't desired. The caller is responsible for setting the active tab's #active property to TRUE.

Parameters

$display_id: The display_id which is edited on the current request.

2 calls to ViewFormBase::getDisplayTabs()
ViewEditForm::renderDisplayTop in core/modules/views_ui/src/ViewEditForm.php
Render the top of the display so it can be updated during ajax operations.
ViewFormBase::prepareEntity in core/modules/views_ui/src/ViewFormBase.php
Prepares the entity object before the form is built first.

File

core/modules/views_ui/src/ViewFormBase.php, line 87

Class

ViewFormBase
Base form for Views forms.

Namespace

Drupal\views_ui

Code

public function getDisplayTabs(ViewUI $view) {
    $executable = $view->getExecutable();
    $executable->initDisplay();
    $display_id = $this->displayID;
    $tabs = [];
    // Create a tab for each display.
    foreach ($view->get('display') as $id => $display) {
        // Get an instance of the display plugin, to make sure it will work in the
        // UI.
        $display_plugin = $executable->displayHandlers
            ->get($id);
        if (empty($display_plugin)) {
            continue;
        }
        $tabs[$id] = [
            '#theme' => 'menu_local_task',
            '#weight' => $display['position'],
            '#link' => [
                'title' => $this->getDisplayLabel($view, $id),
                'localized_options' => [],
                'url' => $view->toUrl('edit-display-form')
                    ->setRouteParameter('display_id', $id),
            ],
        ];
        if (!empty($display['deleted'])) {
            $tabs[$id]['#link']['localized_options']['attributes']['class'][] = 'views-display-deleted-link';
        }
        if (isset($display['display_options']['enabled']) && !$display['display_options']['enabled']) {
            $tabs[$id]['#link']['localized_options']['attributes']['class'][] = 'views-display-disabled-link';
        }
    }
    // If the default display isn't supposed to be shown, don't display its tab, unless it's the only display.
    if (!$this->isDefaultDisplayShown($view) && $display_id != 'default' && count($tabs) > 1) {
        $tabs['default']['#access'] = FALSE;
    }
    // Mark the display tab as red to show validation errors.
    $errors = $executable->validate();
    foreach ($view->get('display') as $id => $display) {
        if (!empty($errors[$id])) {
            // Always show the tab.
            $tabs[$id]['#access'] = TRUE;
            // Add a class to mark the error and a title to make a hover tip.
            $tabs[$id]['#link']['localized_options']['attributes']['class'][] = 'error';
            $tabs[$id]['#link']['localized_options']['attributes']['title'] = $this->t('This display has one or more validation errors.');
        }
    }
    return $tabs;
}

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