This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/vendor/chi-teck/drupal-code-generator/templates/d8/service/route-subscriber.twig
2018-11-23 12:29:20 +00:00

40 lines
972 B
Twig

<?php
namespace Drupal\{{ machine_name }}\EventSubscriber;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Symfony\Component\Routing\RouteCollection;
/**
* {{ name }} route subscriber.
*/
class {{ class }} extends RouteSubscriberBase {
/**
* {@inheritdoc}
*/
protected function alterRoutes(RouteCollection $collection) {
foreach ($collection->all() as $route) {
// Hide taxonomy pages from unprivileged users.
if (strpos($route->getPath(), '/taxonomy/term') === 0) {
$route->setRequirement('_role', 'administrator');
}
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
// Use a lower priority than \Drupal\views\EventSubscriber\RouteSubscriber
// to ensure the requirement will be added to its routes.
$events[RoutingEvents::ALTER] = ['onAlterRoutes', -300];
return $events;
}
}