Skip to content

Instantly share code, notes, and snippets.

@jleehr
Last active August 13, 2020 13:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jleehr/2c3c324a9654596842fb62740baf0023 to your computer and use it in GitHub Desktop.
Save jleehr/2c3c324a9654596842fb62740baf0023 to your computer and use it in GitHub Desktop.
[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

[Drupal 8] Alter route (permissions) for taxonomy vocabulary page

Needs the patch: https://www.drupal.org/node/1848686

Split "Administer vocabularies and terms" permission: Access the taxonomy overview page and Add terms in vocabulary name

File structure:

mymodule
|- src
|-- Routing
|--- RouteSubscriber.php
|- mymodule.services.yml```
services:
myModule.route_subscriber:
class: Drupal\myModule\Routing\RouteSubscriber
tags:
- { name: event_subscriber }
<?php
namespace Drupal\myModule\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
/**
* Listens to the dynamic route events.
*/
class RouteSubscriber extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
// As taxonomy are listing should be easily available.
// In order to do that, override admin/structure to show taxonomy listing.
$route = $collection->get('system.admin_structure');
if ($route) {
$route->setRequirements([
'_permission' => 'access administration pages+access taxonomy overview',
]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment