diff --git a/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php new file mode 100644 index 0000000..8860b11 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php @@ -0,0 +1,49 @@ +add($route);. + * + * @param \Symfony\Component\Routing\RouteCollection $collection + * The route collection for adding routes. + */ + abstract public function routes(RouteCollection $collection); + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $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",