function VocabularyListBuilder::getDefaultOperations

Same name and namespace in other branches
  1. 11.x core/modules/taxonomy/src/VocabularyListBuilder.php \Drupal\taxonomy\VocabularyListBuilder::getDefaultOperations()
  2. 10 core/modules/taxonomy/src/VocabularyListBuilder.php \Drupal\taxonomy\VocabularyListBuilder::getDefaultOperations()
  3. 9 core/modules/taxonomy/src/VocabularyListBuilder.php \Drupal\taxonomy\VocabularyListBuilder::getDefaultOperations()
  4. 8.9.x core/modules/taxonomy/src/VocabularyListBuilder.php \Drupal\taxonomy\VocabularyListBuilder::getDefaultOperations()

Overrides ConfigEntityListBuilder::getDefaultOperations

File

core/modules/taxonomy/src/VocabularyListBuilder.php, line 109

Class

VocabularyListBuilder
Defines a class to build a listing of taxonomy vocabulary entities.

Namespace

Drupal\taxonomy

Code

protected function getDefaultOperations(EntityInterface $entity) {
  $args = func_get_args();
  $cacheability = $args[1] ?? new CacheableMetadata();
  $operations = parent::getDefaultOperations($entity, $cacheability);
  if (isset($operations['edit'])) {
    $operations['edit']['title'] = $this->t('Edit vocabulary');
  }
  if (isset($operations['delete'])) {
    $operations['delete']['title'] = $this->t('Delete vocabulary');
  }
  $overview_access = $entity->access('access taxonomy overview', return_as_object: TRUE);
  $cacheability->addCacheableDependency($overview_access);
  if ($overview_access->isAllowed()) {
    $operations['list'] = [
      'title' => $this->t('List terms'),
      'weight' => 0,
      'url' => $entity->toUrl('overview-form'),
    ];
  }
  $taxonomy_term_access_control_handler = $this->entityTypeManager
    ->getAccessControlHandler('taxonomy_term');
  $create_access = $taxonomy_term_access_control_handler->createAccess($entity->id(), return_as_object: TRUE);
  if ($create_access->isAllowed()) {
    $operations['add'] = [
      'title' => $this->t('Add terms'),
      'weight' => 10,
      'url' => Url::fromRoute('entity.taxonomy_term.add_form', [
        'taxonomy_vocabulary' => $entity->id(),
      ]),
    ];
  }
  return $operations;
}

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