function ViewEditForm::renderDisplayTop

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::renderDisplayTop()
  2. 8.9.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::renderDisplayTop()
  3. 11.x core/modules/views_ui/src/ViewEditForm.php \Drupal\views_ui\ViewEditForm::renderDisplayTop()

Render the top of the display so it can be updated during ajax operations.

2 calls to ViewEditForm::renderDisplayTop()
ViewEditForm::form in core/modules/views_ui/src/ViewEditForm.php
Gets the actual form array to be built.
ViewEditForm::rebuildCurrentTab in core/modules/views_ui/src/ViewEditForm.php
Regenerate the current tab for AJAX updates.

File

core/modules/views_ui/src/ViewEditForm.php, line 744

Class

ViewEditForm
Form controller for the Views edit form.

Namespace

Drupal\views_ui

Code

public function renderDisplayTop(ViewUI $view) {
    $display_id = $this->displayID;
    $element['#theme_wrappers'][] = 'views_ui_container';
    $element['#attributes']['class'] = [
        'views-display-top',
        'clearfix',
    ];
    $element['#attributes']['id'] = [
        'views-display-top',
    ];
    // Extra actions for the display
    $element['extra_actions'] = [
        '#type' => 'dropbutton',
        '#attributes' => [
            'id' => 'views-display-extra-actions',
        ],
        '#links' => [
            'edit-details' => [
                'title' => $this->t('Edit view name/description'),
                'url' => Url::fromRoute('views_ui.form_edit_details', [
                    'js' => 'nojs',
                    'view' => $view->id(),
                    'display_id' => $display_id,
                ]),
                'attributes' => [
                    'class' => [
                        'views-ajax-link',
                    ],
                ],
            ],
            'analyze' => [
                'title' => $this->t('Analyze view'),
                'url' => Url::fromRoute('views_ui.form_analyze', [
                    'js' => 'nojs',
                    'view' => $view->id(),
                    'display_id' => $display_id,
                ]),
                'attributes' => [
                    'class' => [
                        'views-ajax-link',
                    ],
                ],
            ],
            'duplicate' => [
                'title' => $this->t('Duplicate view'),
                'url' => $view->toUrl('duplicate-form'),
            ],
            'reorder' => [
                'title' => $this->t('Reorder displays'),
                'url' => Url::fromRoute('views_ui.form_reorder_displays', [
                    'js' => 'nojs',
                    'view' => $view->id(),
                    'display_id' => $display_id,
                ]),
                'attributes' => [
                    'class' => [
                        'views-ajax-link',
                    ],
                ],
            ],
        ],
    ];
    if ($view->access('delete')) {
        $element['extra_actions']['#links']['delete'] = [
            'title' => $this->t('Delete view'),
            'url' => $view->toUrl('delete-form'),
        ];
    }
    // Let other modules add additional links here.
    $this->moduleHandler
        ->alter('views_ui_display_top_links', $element['extra_actions']['#links'], $view, $display_id);
    if (isset($view->type) && $view->type != $this->t('Default')) {
        if ($view->type == $this->t('Overridden')) {
            $element['extra_actions']['#links']['revert'] = [
                'title' => $this->t('Revert view'),
                'href' => "admin/structure/views/view/{$view->id()}/revert",
                'query' => [
                    'destination' => $view->toUrl('edit-form')
                        ->toString(),
                ],
            ];
        }
        else {
            $element['extra_actions']['#links']['delete'] = [
                'title' => $this->t('Delete view'),
                'url' => $view->toUrl('delete-form'),
            ];
        }
    }
    // Determine the displays available for editing.
    if ($tabs = $this->getDisplayTabs($view)) {
        if ($display_id) {
            $tabs[$display_id]['#active'] = TRUE;
        }
        $tabs['#prefix'] = '<h2 class="visually-hidden">' . $this->t('Secondary tabs') . '</h2><ul id = "views-display-menu-tabs" class="tabs secondary">';
        $tabs['#suffix'] = '</ul>';
        $element['tabs'] = $tabs;
    }
    // Buttons for adding a new display.
    foreach (Views::fetchPluginNames('display', NULL, [
        $view->get('base_table'),
    ]) as $type => $label) {
        $element['add_display'][$type] = [
            '#type' => 'submit',
            '#value' => $this->t('Add @display', [
                '@display' => $label,
            ]),
            '#limit_validation_errors' => [],
            '#submit' => [
                '::submitDisplayAdd',
                '::submitDelayDestination',
            ],
            '#attributes' => [
                'class' => [
                    'add-display',
                ],
                'data-drupal-dropdown-label' => $label,
            ],
            // Allow JavaScript to remove the 'Add ' prefix from the button label when
            // placing the button in an "Add" dropdown menu.
'#process' => array_merge([
                'views_ui_form_button_was_clicked',
            ], $this->elementInfo
                ->getInfoProperty('submit', '#process', [])),
            '#values' => [
                $this->t('Add @display', [
                    '@display' => $label,
                ]),
                $label,
            ],
        ];
    }
    // In AJAX context, ViewUI::rebuildCurrentTab() returns this outside of form
    // context, so hook_form_view_edit_form_alter() is insufficient.
    // @todo remove this after
    //   https://www.drupal.org/project/drupal/issues/3087455 has been resolved.
    $this->moduleHandler
        ->alter('views_ui_display_top', $element, $view, $display_id);
    // Because themes can implement hook_form_FORM_ID_alter() and because this
    // is a workaround for hook_form_view_edit_form_alter() being insufficient,
    // also invoke this on themes.
    // @todo remove this after
    //   https://www.drupal.org/project/drupal/issues/3087455 has been resolved.
    $this->themeManager
        ->alter('views_ui_display_top', $element, $view, $display_id);
    return $element;
}

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