function VocabularyListBuilder::render

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

Overrides DraggableListBuilder::render

File

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

Class

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

Namespace

Drupal\taxonomy

Code

public function render() {
    $entities = $this->load();
    // If there are not multiple vocabularies, disable dragging by unsetting the
    // weight key.
    if (count($entities) <= 1) {
        unset($this->weightKey);
    }
    $build = parent::render();
    // If the weight key was unset then the table is in the 'table' key,
    // otherwise in vocabularies. The empty message is only needed if the table
    // is possibly empty, so there is no need to support the vocabularies key
    // here.
    if (isset($build['table'])) {
        $access_control_handler = $this->entityTypeManager
            ->getAccessControlHandler('taxonomy_vocabulary');
        $create_access = $access_control_handler->createAccess(NULL, NULL, [], TRUE);
        $this->renderer
            ->addCacheableDependency($build['table'], $create_access);
        if ($create_access->isAllowed()) {
            $build['table']['#empty'] = t('No vocabularies available. <a href=":link">Add vocabulary</a>.', [
                ':link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString(),
            ]);
        }
        else {
            $build['table']['#empty'] = t('No vocabularies available.');
        }
    }
    return $build;
}

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