RouteSubscriberBase.php 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Drupal\Core\Routing;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\Routing\RouteCollection;
  5. /**
  6. * Provides a base implementation for RouteSubscriber.
  7. */
  8. abstract class RouteSubscriberBase implements EventSubscriberInterface {
  9. /**
  10. * Alters existing routes for a specific collection.
  11. *
  12. * @param \Symfony\Component\Routing\RouteCollection $collection
  13. * The route collection for adding routes.
  14. */
  15. abstract protected function alterRoutes(RouteCollection $collection);
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public static function getSubscribedEvents() {
  20. $events[RoutingEvents::ALTER] = 'onAlterRoutes';
  21. return $events;
  22. }
  23. /**
  24. * Delegates the route altering to self::alterRoutes().
  25. *
  26. * @param \Drupal\Core\Routing\RouteBuildEvent $event
  27. * The route build event.
  28. */
  29. public function onAlterRoutes(RouteBuildEvent $event) {
  30. $collection = $event->getRouteCollection();
  31. $this->alterRoutes($collection);
  32. }
  33. }