function ViewsUiHooks::entityOperation

Implements hook_entity_operation().

Attributes

#[Hook('entity_operation')]

File

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

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' => $this->t('Edit view'),
          'url' => Url::fromRoute('entity.view.edit_display_form', [
            'view' => $view_id,
            'display_id' => $display_id,
          ]),
          'weight' => 50,
        ];
      }
    }
  }
  return $operations;
}

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