diff --git a/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php index a0f40d2..8860b11 100644 --- a/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php +++ b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php @@ -2,15 +2,14 @@ /** * @file - * Contains \Drupal\Core\Routing\RouteSubsriberBase + * Contains \Drupal\Core\Routing\RouteSubscriberBase */ namespace Drupal\Core\Routing; -use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Core\Routing\RoutingEvents; - use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Routing\RouteCollection; /** * Provides a base implementation for RouteSubscriber. @@ -18,18 +17,33 @@ abstract class RouteSubscriberBase implements EventSubscriberInterface { /** - * Use this to create all dynamic routes. + * Provides new routes by adding them to the collection. + * + * Subclasses should use this method and add \Symfony\Component\Routing\Route + * objects with $collection->add($route);. * - * @param RouteBuildEvent $event + * @param \Symfony\Component\Routing\RouteCollection $collection + * The route collection for adding routes. */ - abstract public function routes(RouteBuildEvent $event); + abstract public function routes(RouteCollection $collection); /** * {@inheritdoc} */ public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; + $events[RoutingEvents::DYNAMIC] = 'getRoutes'; return $events; } + /** + * Delegates the route gathering to self::routes(). + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route build event. + */ + public function getRoutes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + $this->routes($collection); + } + } diff --git a/core/modules/comment/lib/Drupal/comment/Routing/RouteSubscriber.php b/core/modules/comment/lib/Drupal/comment/Routing/RouteSubscriber.php index 354af6f..5547483 100644 --- a/core/modules/comment/lib/Drupal/comment/Routing/RouteSubscriber.php +++ b/core/modules/comment/lib/Drupal/comment/Routing/RouteSubscriber.php @@ -7,16 +7,15 @@ namespace Drupal\comment\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Routing\Route; use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Routing\RouteSubscriberBase; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Defines a route subscriber for the comment module. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** * The module handler service. @@ -38,19 +37,8 @@ public function __construct(ModuleHandlerInterface $module_handler) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * If node module is present, adds the legacy /comment/{node}/reply route. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route build event. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + public function routes(RouteCollection $collection) { + // If node module is present, adds the legacy /comment/{node}/reply route. if ($this->moduleHandler->moduleExists('node')) { $route = new Route( "/comment/{node}/reply",