Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ViewsUiHooks.php

function ViewsUiHooks::entityOperation

Implements hook_entity_operation().

File

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

Class

ViewsUiHooks
Hook implementations for views_ui.

Namespace

Drupal\views_ui\Hook

Code

public function entityOperation(EntityInterface $entity) : array {
    $operations = [];
    if ($entity instanceof BlockInterface) {
        $plugin = $entity->getPlugin();
        if ($plugin->getBaseId() === 'views_block') {
            $view_id_parts = explode('-', $plugin->getDerivativeId());
            $view_id = $view_id_parts[0] ?? '';
            $display_id = $view_id_parts[1] ?? '';
            $view = View::load($view_id);
            if ($view && $view->access('edit')) {
                $operations['view-edit'] = [
                    'title' => t('Edit view'),
                    'url' => Url::fromRoute('entity.view.edit_display_form', [
                        'view' => $view_id,
                        'display_id' => $display_id,
                    ]),
                    'weight' => 50,
                ];
            }
        }
    }
    return $operations;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal