function ViewsUiHooks::contextualLinksViewAlter

Implements hook_contextual_links_view_alter().

File

core/modules/views_ui/src/Hook/ViewsUiHooks.php, line 174

Class

ViewsUiHooks
Hook implementations for views_ui.

Namespace

Drupal\views_ui\Hook

Code

public function contextualLinksViewAlter(&$element, $items) {
    // Remove contextual links from being rendered, when so desired, such as
    // within a View preview.
    if (views_ui_contextual_links_suppress()) {
        $element['#links'] = [];
    }
    elseif (!empty($element['#links']['entityviewedit-form'])) {
        $display_id = $items['entity.view.edit_form']['metadata']['display_id'];
        $route_parameters = $element['#links']['entityviewedit-form']['url']->getRouteParameters() + [
            'display_id' => $display_id,
        ];
        $element['#links']['entityviewedit-form']['url'] = Url::fromRoute('entity.view.edit_display_form', $route_parameters);
    }
}

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