3 namespace Drupal\Core\EventSubscriber;
5 use Drupal\Core\Routing\LazyRouteEnhancer;
6 use Drupal\Core\Routing\RouteBuildEvent;
7 use Drupal\Core\Routing\RoutingEvents;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11 * Listens to the new routes before they get saved.
13 class RouteEnhancerSubscriber implements EventSubscriberInterface {
16 * @var \Drupal\Core\Routing\LazyRouteEnhancer
18 protected $routeEnhancer;
21 * Constructs the RouteEnhancerSubscriber object.
23 * @param \Drupal\Core\Routing\LazyRouteEnhancer $route_enhancer
24 * The lazy route enhancer.
26 public function __construct(LazyRouteEnhancer $route_enhancer) {
27 $this->routeEnhancer = $route_enhancer;
31 * Adds the route_enhancer object to the route collection.
33 * @param \Drupal\Core\Routing\RouteBuildEvent $event
34 * The route build event.
36 public function onRouteAlter(RouteBuildEvent $event) {
37 $this->routeEnhancer->setEnhancers($event->getRouteCollection());
43 public static function getSubscribedEvents() {
44 $events[RoutingEvents::ALTER][] = ['onRouteAlter', -300];