You are here

public function ViewListBuilder::getDefaultOperations in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDefaultOperations()

Gets this list's default operations.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity the operations are for.

Return value

array The array structure is identical to the return value of self::getOperations().

Overrides ConfigEntityListBuilder::getDefaultOperations

File

core/modules/views_ui/src/ViewListBuilder.php, line 162

Class

ViewListBuilder
Defines a class to build a listing of view entities.

Namespace

Drupal\views_ui

Code

public function getDefaultOperations(EntityInterface $entity) {
  $operations = parent::getDefaultOperations($entity);

  // Remove destination redirect for Edit operation.
  $operations['edit']['url'] = $entity
    ->toUrl('edit-form');
  if ($entity
    ->hasLinkTemplate('duplicate-form')) {
    $operations['duplicate'] = [
      'title' => $this
        ->t('Duplicate'),
      'weight' => 15,
      'url' => $entity
        ->toUrl('duplicate-form'),
    ];
  }

  // Add AJAX functionality to enable/disable operations.
  foreach ([
    'enable',
    'disable',
  ] as $op) {
    if (isset($operations[$op])) {
      $operations[$op]['url'] = $entity
        ->toUrl($op);

      // Enable and disable operations should use AJAX.
      $operations[$op]['attributes']['class'][] = 'use-ajax';
    }
  }

  // ajax.js focuses automatically on the data-drupal-selector element. When
  // enabling the view again, focusing on the disable link doesn't work, as it
  // is hidden. We assign data-drupal-selector to every link, so it focuses
  // on the edit link.
  foreach ($operations as &$operation) {
    $operation['attributes']['data-drupal-selector'] = 'views-listing-' . $entity
      ->id();
  }
  return $operations;
}