diff --git a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php index 2ab8cdb..f3320db 100644 --- a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php +++ b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php @@ -8,15 +8,13 @@ namespace Drupal\views\EventSubscriber; use Drupal\Component\Utility\MapArray; -use Drupal\Component\Utility\NestedArray; use Drupal\Core\DestructableInterface; use Drupal\Core\Entity\EntityManager; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; +use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\views\Plugin\views\display\DisplayRouterInterface; use Drupal\views\ViewExecutable; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Routing\RouteCollection; /** * Builds up the routes of all views. @@ -27,7 +25,7 @@ * * @see \Drupal\views\Plugin\views\display\PathPluginBase */ -class RouteSubscriber implements EventSubscriberInterface, DestructableInterface { +class RouteSubscriber extends RouteSubscriberBase implements DestructableInterface { /** * Stores a list of view,display IDs which haven't be used in the alter event. @@ -78,15 +76,6 @@ public function reset() { } /** - * {@inheritdoc} - */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'dynamicRoutes'; - $events[RoutingEvents::ALTER] = 'alterRoutes'; - return $events; - } - - /** * Gets all the views and display IDs using a route. */ protected function getViewsDisplayIDsWithRoute() { @@ -106,14 +95,9 @@ protected function getViewsDisplayIDsWithRoute() { } /** - * Adds routes defined by all views. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. + * {@inheritdoc} */ - public function dynamicRoutes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); - + protected function routes(RouteCollection $collection) { foreach ($this->getViewsDisplayIDsWithRoute() as $pair) { list($view_id, $display_id) = explode('.', $pair); $view = $this->viewStorageController->load($view_id); @@ -134,12 +118,9 @@ public function dynamicRoutes(RouteBuildEvent $event) { } /** - * Alters existing routes. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. + * {@inheritdoc} */ - public function alterRoutes(RouteBuildEvent $event) { + protected function alterRoutes(RouteCollection $collection, $module) { foreach ($this->getViewsDisplayIDsWithRoute() as $pair) { list($view_id, $display_id) = explode('.', $pair); $view = $this->viewStorageController->load($view_id); @@ -149,7 +130,7 @@ public function alterRoutes(RouteBuildEvent $event) { if ($display instanceof DisplayRouterInterface) { // If the display returns TRUE a route item was found, so it does not // have to be added. - $view_route_names = $display->alterRoutes($event->getRouteCollection()); + $view_route_names = $display->alterRoutes($collection); $this->viewRouteNames += $view_route_names; foreach ($view_route_names as $id_display => $route_name) { unset($this->viewsDisplayPairs[$id_display]); diff --git a/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php b/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php index a6a6d7c..0d40f0c 100644 --- a/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php +++ b/core/modules/views/tests/Drupal/views/Tests/EventSubscriber/RouteSubscriberTest.php @@ -75,9 +75,9 @@ protected function setUp() { } /** - * Tests the dynamicRoutes method. + * Tests the onDynamicRoutes method. * - * @see \Drupal\views\EventSubscriber\RouteSubscriber::dynamicRoutes() + * @see \Drupal\views\EventSubscriber\RouteSubscriber::onDynamicRoutes() */ public function testDynamicRoutes() { $collection = new RouteCollection(); @@ -92,7 +92,7 @@ public function testDynamicRoutes() { ->method('collectRoutes') ->will($this->returnValue(array('test_id.page_2' => 'views.test_id.page_2'))); - $this->assertNull($this->routeSubscriber->dynamicRoutes($route_event)); + $this->assertNull($this->routeSubscriber->onDynamicRoutes($route_event)); $this->state->expects($this->once()) ->method('set') @@ -101,9 +101,9 @@ public function testDynamicRoutes() { } /** - * Tests the alterRoutes method. + * Tests the onAlterRoutes method. * - * @see \Drupal\views\EventSubscriber\RouteSubscriber::alterRoutes() + * @see \Drupal\views\EventSubscriber\RouteSubscriber::onAlterRoutes() */ public function testAlterRoutes() { $collection = new RouteCollection(); @@ -130,12 +130,12 @@ public function testAlterRoutes() { ->method('collectRoutes') ->will($this->returnValue(array('test_id.page_2' => 'views.test_id.page_2'))); - $this->assertNull($this->routeSubscriber->alterRoutes($route_event)); + $this->assertNull($this->routeSubscriber->onAlterRoutes($route_event)); // Ensure that after the alterRoutes the collectRoutes method is just called // once (not for page_1 anymore). - $this->assertNull($this->routeSubscriber->dynamicRoutes($route_event)); + $this->assertNull($this->routeSubscriber->onDynamicRoutes($route_event)); $this->state->expects($this->once()) ->method('set')