function ViewListBuilder::getDefaultOperations

Same name in other branches
  1. 9 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDefaultOperations()
  2. 8.9.x core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDefaultOperations()
  3. 10 core/modules/views_ui/src/ViewListBuilder.php \Drupal\views_ui\ViewListBuilder::getDefaultOperations()

Overrides ConfigEntityListBuilder::getDefaultOperations

File

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

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;
}

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