diff --git a/core/lib/Drupal/Core/EventSubscriber/ModuleRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ModuleRouteSubscriber.php index 5bb903ef9f5b3e9931131e43223612984f7f3801..49f1a124cf9c37c9b1219fd063caef63791a5b5c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ModuleRouteSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/ModuleRouteSubscriber.php @@ -8,14 +8,13 @@ namespace Drupal\Core\EventSubscriber; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Routing\RouteBuildEvent; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Drupal\Core\Routing\RoutingEvents; +use Drupal\Core\Routing\RouteSubscriberBase; +use Symfony\Component\Routing\RouteCollection; /** * A route subscriber to remove routes that depend on modules being enabled. */ -class ModuleRouteSubscriber implements EventSubscriberInterface { +class ModuleRouteSubscriber extends RouteSubscriberBase { /** * The module handler. @@ -37,20 +36,7 @@ public function __construct(ModuleHandlerInterface $module_handler) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::ALTER] = 'removeRoutes'; - return $events; - } - - /** - * Removes any routes that have an unmet module dependency. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function removeRoutes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); - + protected function alterRoutes(RouteCollection $collection, $module) { foreach ($collection as $name => $route) { if ($route->hasRequirement('_module_dependencies')) { $modules = $route->getRequirement('_module_dependencies'); diff --git a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php index 22e82d2959ec39ecf2908946855a496f3adca7de..39f9cebd0f655fa11772ee3e9c5719ddd00d3659 100644 --- a/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php @@ -9,25 +9,19 @@ use Drupal\Component\Utility\String; use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Cmf\Component\Routing\RouteObjectInterface; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Symfony\Component\Routing\RouteCollection; /** * Provides a route subscriber which checks for invalid pattern variables. */ -class SpecialAttributesRouteSubscriber implements EventSubscriberInterface { +class SpecialAttributesRouteSubscriber extends RouteSubscriberBase { /** - * Checks for invalid pattern variables. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The event containing the build routes. - * - * @throws \InvalidArgumentException - * Thrown when a reserved variable was used as route variable. + * {@inheritdoc} */ - public function onRouteBuilding(RouteBuildEvent $event) { + protected function alterRoutes(RouteCollection $collection, $module) { $special_variables = array( '_account', 'system_path', @@ -41,7 +35,7 @@ public function onRouteBuilding(RouteBuildEvent $event) { '_form', ); - foreach ($event->getRouteCollection()->all() as $route) { + foreach ($collection->all() as $route) { if ($not_allowed_variables = array_intersect($route->compile()->getVariables(), $special_variables)) { $placeholders = array('@variables' => implode(', ', $not_allowed_variables)); drupal_set_message(String::format('The following variables are reserved names by drupal: @variables', $placeholders)); @@ -53,11 +47,17 @@ public function onRouteBuilding(RouteBuildEvent $event) { } /** - * {@inheritdoc} + * Delegates the route altering to self::alterRoutes(). + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route build event. + * + * @return bool + * Returns TRUE if the variables were succesfully replaced, otherwise FALSE. */ - static function getSubscribedEvents() { - $events[RoutingEvents::ALTER][] = 'onRouteBuilding'; - return $events; + public function onAlterRoutes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + return $this->alterRoutes($collection, $event->getModule()); } } diff --git a/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php new file mode 100644 index 0000000000000000000000000000000000000000..615a82091799b1b0db65f0a8f4a409caaa920238 --- /dev/null +++ b/core/lib/Drupal/Core/Routing/RouteSubscriberBase.php @@ -0,0 +1,74 @@ +add($route);. + * + * @param \Symfony\Component\Routing\RouteCollection $collection + * The route collection for adding routes. + */ + protected function routes(RouteCollection $collection) { + } + + /** + * Alters existing routes for a specific collection. + * + * @param \Symfony\Component\Routing\RouteCollection $collection + * The route collection for adding routes. + * @param string $module + * The module these routes belong to. For dynamically added routes, the + * module name will be 'dynamic_routes'. + */ + protected function alterRoutes(RouteCollection $collection, $module) { + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() { + $events[RoutingEvents::DYNAMIC] = 'onDynamicRoutes'; + $events[RoutingEvents::ALTER] = 'onAlterRoutes'; + return $events; + } + + /** + * Delegates the route gathering to self::routes(). + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route build event. + */ + public function onDynamicRoutes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + $this->routes($collection); + } + + /** + * Delegates the route altering to self::alterRoutes(). + * + * @param \Drupal\Core\Routing\RouteBuildEvent $event + * The route build event. + */ + public function onAlterRoutes(RouteBuildEvent $event) { + $collection = $event->getRouteCollection(); + $this->alterRoutes($collection, $event->getModule()); + } + +} diff --git a/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php index 843e778005d92e85bd1416f6d0e649df488910e6..ce49b779376b314bcb8cee984fd71213da016a54 100644 --- a/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php +++ b/core/modules/block/lib/Drupal/block/Routing/RouteSubscriber.php @@ -7,36 +7,19 @@ namespace Drupal\block\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\Route; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Routing\RouteCollection; /** * Provides dynamic routes for various block pages. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** - * Implements EventSubscriberInterface::getSubscribedEvents(). + * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * Generates dynamic routes for various block pages. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - * - * @return \Symfony\Component\Routing\RouteCollection - * The route collection that contains the new dynamic route. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + protected function routes(RouteCollection $collection) { foreach (list_themes(TRUE) as $key => $theme) { // The block entity listing page. $route = new Route( diff --git a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php index cb4858c55a6a91f420a98d302d8484cb607b9c51..ae4a55c02793785e403adc02a7dbf9709d4e3487 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php @@ -7,16 +7,15 @@ namespace Drupal\content_translation\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; use Drupal\Core\Entity\EntityManager; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Subscriber for entity translation routes. */ -class ContentTranslationRouteSubscriber implements EventSubscriberInterface { +class ContentTranslationRouteSubscriber extends RouteSubscriberBase { /** * The entity type manager. @@ -38,16 +37,7 @@ public function __construct(EntityManager $entityManager) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * Adds routes for entity translations. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + protected function routes(RouteCollection $collection) { foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) { if ($entity_info['translatable'] && isset($entity_info['translation'])) { $path = '/' . str_replace($entity_info['menu_path_wildcard'], '{' . $entity_type . '}', $entity_info['menu_base_path']) . '/translations'; diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php index 456e1fda4e7526165d552bf23dcbdc366dd7463e..6e3b003ec509bccd8cb2cabba7591ee5b9f698a7 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php @@ -7,16 +7,15 @@ namespace Drupal\field_ui\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; -use Symfony\Component\Routing\Route; use Drupal\Core\Entity\EntityManager; +use Drupal\Core\Routing\RouteSubscriberBase; +use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Subscriber for Field UI routes. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** * The entity type manager @@ -38,16 +37,7 @@ public function __construct(EntityManager $manager) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * Adds routes for the Field UI. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + protected function routes(RouteCollection $collection) { foreach ($this->manager->getDefinitions() as $entity_type => $entity_info) { $defaults = array(); if ($entity_info['fieldable'] && isset($entity_info['route_base_path'])) { diff --git a/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php b/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php index 252452224c47dd9ef19926498a587f635a0aa4f2..59fbb75798bf326a562078c6febf755445d9e5f6 100644 --- a/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php +++ b/core/modules/image/lib/Drupal/image/EventSubscriber/RouteSubscriber.php @@ -7,38 +7,23 @@ namespace Drupal\image\EventSubscriber; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Defines a route subscriber to register a url for serving image styles. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'dynamicRoutes'; - return $events; - } - - /** - * Registers dynamic routes for image styles. - * - * Generate image derivatives of publicly available files. If clean URLs are - * disabled, image derivatives will always be served through the menu system. - * If clean URLs are enabled and the image derivative already exists, PHP will - * be bypassed. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function dynamicRoutes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); - + protected function routes(RouteCollection $collection) { + // Generate image derivatives of publicly available files. If clean URLs are + // disabled image derivatives will always be served through the menu system. + // If clean URLs are enabled and the image derivative already exists, PHP + // will be bypassed. $directory_path = file_stream_wrapper_get_instance_by_scheme('public')->getDirectoryPath(); $route = new Route('/' . $directory_path . '/styles/{image_style}/{scheme}', diff --git a/core/modules/rest/lib/Drupal/rest/EventSubscriber/RouteSubscriber.php b/core/modules/rest/lib/Drupal/rest/EventSubscriber/RouteSubscriber.php index 325f4726f06f741e954d3f571ccd37e81c250fb5..34fd75d2619550494d0665ab162abe24138520b7 100644 --- a/core/modules/rest/lib/Drupal/rest/EventSubscriber/RouteSubscriber.php +++ b/core/modules/rest/lib/Drupal/rest/EventSubscriber/RouteSubscriber.php @@ -1,22 +1,21 @@ getRouteCollection(); + protected function routes(RouteCollection $collection) { $enabled_resources = $this->config->get('rest.settings')->load()->get('resources'); // Iterate over all enabled resource plugins. @@ -88,12 +82,4 @@ public function dynamicRoutes(RouteBuildEvent $event) { } } - /** - * Implements EventSubscriberInterface::getSubscribedEvents(). - */ - static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'dynamicRoutes'; - return $events; - } } - diff --git a/core/modules/search/lib/Drupal/search/Routing/SearchRouteSubscriber.php b/core/modules/search/lib/Drupal/search/Routing/SearchRouteSubscriber.php index 5564ba4cc9961d6be8b68c1b20e67620c7fd8aa4..0061d83ea0ed7b834fb08c51eef28f1318899cba 100644 --- a/core/modules/search/lib/Drupal/search/Routing/SearchRouteSubscriber.php +++ b/core/modules/search/lib/Drupal/search/Routing/SearchRouteSubscriber.php @@ -2,21 +2,20 @@ /** * @file - * Contains Drupal\search\Routing\SearchRouteSubscriber + * Contains \Drupal\search\Routing\SearchRouteSubscriber. */ namespace Drupal\search\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; +use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\search\SearchPluginManager; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Provides dynamic routes for search. */ -class SearchRouteSubscriber implements EventSubscriberInterface { +class SearchRouteSubscriber extends RouteSubscriberBase { /** * The search plugin manager. @@ -38,20 +37,7 @@ public function __construct(SearchPluginManager $search_plugin_manager) { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * Adds routes for search. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); - + protected function routes(RouteCollection $collection) { foreach ($this->searchManager->getActiveDefinitions() as $plugin_id => $search_info) { $path = 'search/' . $search_info['path'] . '/{keys}'; $defaults = array( diff --git a/core/modules/system/lib/Drupal/system/Routing/RouteSubscriber.php b/core/modules/system/lib/Drupal/system/Routing/RouteSubscriber.php index d9ef34d05789cf73a2c44fc8a145b6a3f5c602c3..de5304eda7e7426a6d867e356fc46ecc9d907967 100644 --- a/core/modules/system/lib/Drupal/system/Routing/RouteSubscriber.php +++ b/core/modules/system/lib/Drupal/system/Routing/RouteSubscriber.php @@ -7,32 +7,19 @@ namespace Drupal\system\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Provides dynamic routes for theme administration. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** - * Implements EventSubscriberInterface::getSubscribedEvents(). + * {@inheritdoc} */ - static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'createSystemThemeRoutes'; - return $events; - } - - /** - * Adds dynamic system theme routes. - * - * @param \Drupal\Core\Routing\RouteBuildEvent $event - * The route building event. - */ - public function createSystemThemeRoutes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + protected function routes(RouteCollection $collection) { foreach (list_themes() as $theme) { if (!empty($theme->status)) { $route = new Route('admin/appearance/settings/' . $theme->name, array( diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php index 8834b4a7d97884b242c6af70d6659e20438d82d5..ae09b5536497f9820bce9a4b581590a6b05b9dd0 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Routing/RouteSubscriber.php @@ -7,29 +7,19 @@ namespace Drupal\entity_test\Routing; -use Drupal\Core\Routing\RouteBuildEvent; -use Drupal\Core\Routing\RoutingEvents; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Drupal\Core\Routing\RouteSubscriberBase; use Symfony\Component\Routing\Route; +use Symfony\Component\Routing\RouteCollection; /** * Subscriber for Entity Test routes. */ -class RouteSubscriber implements EventSubscriberInterface { +class RouteSubscriber extends RouteSubscriberBase { /** * {@inheritdoc} */ - public static function getSubscribedEvents() { - $events[RoutingEvents::DYNAMIC] = 'routes'; - return $events; - } - - /** - * Adds routes for the Entity Test. - */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); + protected function routes(RouteCollection $collection) { $types = entity_test_entity_types(); $types[] = 'entity_test_render'; diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/EventSubscriber/FormTestEventSubscriber.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/EventSubscriber/FormTestEventSubscriber.php index 11e5a7ac9764afcb8703eebbba6673a552b632af..552398bf786a363ba6d37f83e060c66b6e5810be 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/EventSubscriber/FormTestEventSubscriber.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/EventSubscriber/FormTestEventSubscriber.php @@ -7,18 +7,18 @@ namespace Drupal\form_test\EventSubscriber; -use Drupal\Core\Routing\RouteBuildEvent; +use Drupal\Core\Routing\RouteSubscriberBase; use Drupal\Core\Routing\RoutingEvents; use Drupal\Core\Extension\ModuleHandlerInterface; use Symfony\Component\Routing\Route; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Routing\RouteCollection; /** * Test event subscriber to add new attributes to the request. */ -class FormTestEventSubscriber implements EventSubscriberInterface { +class FormTestEventSubscriber extends RouteSubscriberBase { /** * The module handler. @@ -51,18 +51,15 @@ public function onKernelRequest(GetResponseEvent $event) { */ public static function getSubscribedEvents() { $events[KernelEvents::REQUEST][] = array('onKernelRequest'); - $events[RoutingEvents::DYNAMIC] = 'routes'; - + $events[RoutingEvents::DYNAMIC] = 'onDynamicRoutes'; + $events[RoutingEvents::ALTER] = 'onAlterRoutes'; return $events; } /** - * Adds routes for the Form Tests. + * {@inheritdoc} */ - public function routes(RouteBuildEvent $event) { - $collection = $event->getRouteCollection(); - $defaults = array(); - + protected function routes(RouteCollection $collection) { if ($this->moduleHandler->moduleExists('node')) { $route = new Route( "form-test/two-instances-of-same-form", diff --git a/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php b/core/modules/views/lib/Drupal/views/EventSubscriber/RouteSubscriber.php index 2ab8cdbd660d4d62a6cb9348ba7bfb3ab419128b..f3320dbed6556e87636f7c47797cc28dcff02c94 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. @@ -77,15 +75,6 @@ public function reset() { $this->viewsDisplayPairs = NULL; } - /** - * {@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. */ @@ -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/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php index f4209432bf48592628bf9c3bb58e67da93dd79c6..3e5b590dfe3b9b65861d2f4262d3b575a9c1d1fa 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/DisplayPageTest.php @@ -95,7 +95,7 @@ public function testPageResponses() { public function testPageRouterItems() { $subscriber = new RouteSubscriber($this->container->get('entity.manager'), $this->container->get('state')); $collection = new RouteCollection(); - $subscriber->dynamicRoutes(new RouteBuildEvent($collection, 'dynamic_routes')); + $subscriber->onDynamicRoutes(new RouteBuildEvent($collection, 'dynamic_routes')); // Check the controller defaults. foreach ($collection as $id => $route) { 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 a6a6d7cdc432e6b99ed840fe612b7aa0545adaa7..fad9eac7480081cef2f26e891d609e0dc14eb58b 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,11 +101,11 @@ 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() { + public function testOnAlterRoutes() { $collection = new RouteCollection(); $collection->add('test_route', new Route('test_route', array('_controller' => 'Drupal\Tests\Core\Controller\TestController'))); $route_2 = new Route('test_route/example', array('_controller' => 'Drupal\Tests\Core\Controller\TestController')); @@ -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') diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ModuleRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ModuleRouteSubscriberTest.php index aea9434cc9cb54c9b9e8f603f21046859e9a833e..0018ffd41f3ed66615fa4f63c104b37946d7ad6b 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/ModuleRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ModuleRouteSubscriberTest.php @@ -69,7 +69,7 @@ public function testRemoveRoute($route_name, array $requirements, $removed) { $event = new RouteBuildEvent($collection, 'test'); $route_subscriber = new ModuleRouteSubscriber($this->moduleHandler); - $route_subscriber->removeRoutes($event); + $route_subscriber->onAlterRoutes($event); if ($removed) { $this->assertNull($collection->get($route_name)); diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index 7555768394a40b025f1f7bca1d75eaa1703958e2..f003327d9e042f8fb3ff1093c6532d5c58d67688 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -84,7 +84,7 @@ public function providerTestOnRouteBuildingValidVariables() { } /** - * Tests the onRouteBuilding method for valid variables. + * Tests the onAlterRoutes method for valid variables. * * @param \Symfony\Component\Routing\Route $route * The route to check. @@ -95,11 +95,11 @@ public function testOnRouteBuildingValidVariables(Route $route) { $route_collection = new RouteCollection(); $route_collection->add('test', $route); $event = new RouteBuildEvent($route_collection, 'test'); - $this->assertTrue($this->specialAttributesRouteSubscriber->onRouteBuilding($event)); + $this->assertTrue($this->specialAttributesRouteSubscriber->onAlterRoutes($event)); } /** - * Tests the onRouteBuilding method for invalid variables. + * Tests the onAlterRoutes method for invalid variables. * * @param \Symfony\Component\Routing\Route $route * The route to check. @@ -110,7 +110,7 @@ public function testOnRouteBuildingInvalidVariables(Route $route) { $route_collection = new RouteCollection(); $route_collection->add('test', $route); $event = new RouteBuildEvent($route_collection, 'test'); - $this->assertFalse($this->specialAttributesRouteSubscriber->onRouteBuilding($event)); + $this->assertFalse($this->specialAttributesRouteSubscriber->onAlterRoutes($event)); } }