public function MainController::listVocabularies in Taxonomy Manager 8
Same name and namespace in other branches
- 2.0.x src/Controller/MainController.php \Drupal\taxonomy_manager\Controller\MainController::listVocabularies()
List of vocabularies, which link to Taxonomy Manager interface.
Return value
array A render array representing the page.
1 string reference to 'MainController::listVocabularies'
File
- src/
Controller/ MainController.php, line 20
Class
- MainController
- Controller routines for taxonomy_manager routes.
Namespace
Drupal\taxonomy_manager\ControllerCode
public function listVocabularies() {
$new_voc_url = Url::fromRoute('entity.taxonomy_vocabulary.add_form');
$new_voc_admin_link = Link::fromTextAndUrl($this
->t('Add new vocabulary'), $new_voc_url)
->toString();
$edit_voc_url = Url::fromRoute('entity.taxonomy_vocabulary.collection');
$edit_voc_admin_link = Link::fromTextAndUrl($this
->t('Edit vocabulary settings'), $edit_voc_url)
->toString();
$build = [
'#markup' => "{$new_voc_admin_link} | {$edit_voc_admin_link}",
];
$voc_list = [];
$vocabularies = $this
->entityTypeManager()
->getStorage('taxonomy_vocabulary')
->loadMultiple();
foreach ($vocabularies as $vocabulary) {
$vocabulary_form = Url::fromRoute('taxonomy_manager.admin_vocabulary', [
'taxonomy_vocabulary' => $vocabulary
->id(),
]);
$voc_list[] = Link::fromTextAndUrl($vocabulary
->label(), $vocabulary_form);
}
if (!count($voc_list)) {
$voc_list[] = [
'#markup' => $this
->t('No Vocabularies available'),
];
}
$build['vocabularies'] = [
'#theme' => 'item_list',
'#items' => $voc_list,
'#title' => $this
->t('Vocabularies'),
];
return $build;
}