diff --git a/core/modules/taxonomy/src/VocabularyListBuilder.php b/core/modules/taxonomy/src/VocabularyListBuilder.php index 60d89958d3..caf8442cd0 100644 --- a/core/modules/taxonomy/src/VocabularyListBuilder.php +++ b/core/modules/taxonomy/src/VocabularyListBuilder.php @@ -150,13 +150,23 @@ public function render() { unset($this->weightKey); } $build = parent::render(); - $create_access = $this->entityTypeManager->getAccessControlHandler('taxonomy_vocabulary')->createAccess(NULL, NULL, [], TRUE); - $this->renderer->addCacheableDependency($build['table'], $create_access); - if ($create_access->isAllowed()) { - $build['table']['#empty'] = t('No vocabularies available. Add vocabulary.', ['@link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString()]); - } - else { - $build['table']['#empty'] = t('No vocabularies available.'); + + // 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. Add vocabulary.', [ + '@link' => Url::fromRoute('entity.taxonomy_vocabulary.add_form')->toString() + ]); + } + else { + $build['table']['#empty'] = t('No vocabularies available.'); + } } return $build;