Skip to content

Instantly share code, notes, and snippets.

@twfahey1
Forked from jleehr/README.md
Created August 13, 2020 13:59
Show Gist options
  • Save twfahey1/f2063faf0f969af8f25a229c0788488b to your computer and use it in GitHub Desktop.
Save twfahey1/f2063faf0f969af8f25a229c0788488b 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