forked from a64f7bb4-7358-4778-9fbe-3b882c34cc1d/v1
59 lines
1.3 KiB
Twig
59 lines
1.3 KiB
Twig
{% import '_lib/di.twig' as di %}
|
|
<?php
|
|
|
|
namespace Drupal\{{ machine_name }}\EventSubscriber;
|
|
|
|
{% sort %}
|
|
{% if services %}
|
|
{{ di.use(services) }}
|
|
{% endif %}
|
|
use Drupal\Core\Routing\RouteSubscriberBase;
|
|
use Drupal\Core\Routing\RoutingEvents;
|
|
use Symfony\Component\Routing\RouteCollection;
|
|
{% endsort %}
|
|
|
|
/**
|
|
* Route subscriber.
|
|
*/
|
|
class {{ class }} extends RouteSubscriberBase {
|
|
|
|
{% if services %}
|
|
{{ di.properties(services) }}
|
|
|
|
/**
|
|
* Constructs {{ class|article }} object.
|
|
*
|
|
{{ di.annotation(services) }}
|
|
*/
|
|
public function __construct({{ di.signature(services) }}) {
|
|
{{ di.assignment(services) }}
|
|
}
|
|
|
|
{% endif %}
|
|
/**
|
|
* {@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;
|
|
}
|
|
|
|
}
|