From aa0c350766994e5a1f0288496b788019896444df Mon Sep 17 00:00:00 2001 From: naomi Date: Thu, 21 Apr 2022 08:46:13 +0100 Subject: [PATCH] Added links to admin menu for managing taxonomies --- opencase.links.menu.yml | 5 ++ .../Derivative/ManageTaxonomyMenuLink.php | 52 +++++++++++++++++++ src/Plugin/Menu/ManageTaxonomyMenuLink.php | 6 +++ 3 files changed, 63 insertions(+) create mode 100644 src/Plugin/Derivative/ManageTaxonomyMenuLink.php create mode 100644 src/Plugin/Menu/ManageTaxonomyMenuLink.php diff --git a/opencase.links.menu.yml b/opencase.links.menu.yml index 3eb8ffc..046bdc4 100644 --- a/opencase.links.menu.yml +++ b/opencase.links.menu.yml @@ -40,6 +40,11 @@ opencase.opencase_admin_menu: route_name: opencase.opencase_admin_menu menu_name: opencase weight: 100 +opencase.manage_taxonomy_links: + class: Drupal\opencase\Plugin\Menu\ManageTaxonomyMenuLink + deriver: Drupal\opencase\Plugin\Derivative\ManageTaxonomyMenuLink + menu_name: opencase + parent: opencase.opencase_admin_menu opencase.manage_user_logins: title: 'Manage user logins' description: 'Manage who can access the system' diff --git a/src/Plugin/Derivative/ManageTaxonomyMenuLink.php b/src/Plugin/Derivative/ManageTaxonomyMenuLink.php new file mode 100644 index 0000000..76b59b8 --- /dev/null +++ b/src/Plugin/Derivative/ManageTaxonomyMenuLink.php @@ -0,0 +1,52 @@ +entityTypeManager = $entity_type_manager; + } + + /** +   * {@inheritdoc} +   */ + public static function create(ContainerInterface $container, $base_plugin_id) { + return new static( + $base_plugin_id, + $container->get('entity_type.manager') + ); + } + /** +   * {@inheritdoc} +   */ + public function getDerivativeDefinitions($base_plugin_definition) { + $links = []; + $vocabs = $this->entityTypeManager->getStorage('taxonomy_vocabulary')->loadMultiple(); + foreach ($vocabs as $id => $vocab) { + $links[$id] = [ + 'title' => 'Manage ' . $vocab->label(), + 'route_name' => "entity.taxonomy_vocabulary.overview_form", + 'route_parameters' => ['taxonomy_vocabulary' => $vocab->id()] + ] + $base_plugin_definition; + } + return $links; + } +} diff --git a/src/Plugin/Menu/ManageTaxonomyMenuLink.php b/src/Plugin/Menu/ManageTaxonomyMenuLink.php new file mode 100644 index 0000000..0ce23fe --- /dev/null +++ b/src/Plugin/Menu/ManageTaxonomyMenuLink.php @@ -0,0 +1,6 @@ +