diff --git a/core/core.services.yml b/core/core.services.yml index 5e09001..c43950f 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -299,7 +299,7 @@ services: arguments: ['@entity.manager', '@string_translation'] theme_handler: class: Drupal\Core\Extension\ThemeHandler - arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder_indicator'] + arguments: ['@app.root', '@config.factory', '@module_handler', '@state', '@info_parser', '@logger.channel.default', '@asset.css.collection_optimizer', '@config.installer', '@config.manager', '@router.builder'] entity.manager: class: Drupal\Core\Entity\EntityManager arguments: ['@container.namespaces', '@module_handler', '@cache.discovery', '@language_manager', '@string_translation', '@class_resolver', '@typed_data_manager', '@entity.definitions.installed', '@event_dispatcher'] @@ -548,17 +548,9 @@ services: arguments: ['@database', '@state'] tags: - { name: backend_overridable } - router.builder_indicator: - class: Drupal\Core\Routing\RouteBuilderIndicator - arguments: ['@state'] router.builder: class: Drupal\Core\Routing\RouteBuilder - arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@access_manager.check_provider', '@router.builder_indicator'] - router.rebuild_subscriber: - class: Drupal\Core\EventSubscriber\RouterRebuildSubscriber - arguments: ['@router.builder'] - tags: - - { name: event_subscriber } + arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@access_manager.check_provider', '@cache.default'] menu.rebuild_subscriber: class: Drupal\Core\EventSubscriber\MenuRouterRebuildSubscriber arguments: ['@lock', '@plugin.manager.menu.link'] diff --git a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php index 41b5a87..6c4fcba 100644 --- a/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/MenuRouterRebuildSubscriber.php @@ -20,11 +20,6 @@ class MenuRouterRebuildSubscriber implements EventSubscriberInterface { /** - * @var \Drupal\Core\Routing\RouteBuilderInterface - */ - protected $routeBuilder; - - /** * @var \Drupal\Core\Lock\LockBackendInterface */ protected $lock; diff --git a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php deleted file mode 100644 index 584b141..0000000 --- a/core/lib/Drupal/Core/EventSubscriber/RouterRebuildSubscriber.php +++ /dev/null @@ -1,57 +0,0 @@ -routeBuilder = $route_builder; - } - - /** - * Rebuilds routers if necessary. - * - * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event - * The event object. - */ - public function onKernelTerminate(PostResponseEvent $event) { - $this->routeBuilder->rebuildIfNeeded(); - } - - /** - * {@inheritdoc} - */ - static function getSubscribedEvents() { - $events[KernelEvents::TERMINATE][] = array('onKernelTerminate', 200); - return $events; - } - -} diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index c6f3921..a15799c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -201,7 +201,6 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Clear plugin manager caches and flag router to rebuild if requested. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); // Set the schema version to the number of the last update provided by // the module, or the minimum core schema version. @@ -275,6 +274,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // If any modules were newly installed, invoke hook_modules_installed(). if (!empty($modules_installed)) { + \Drupal::service('router.builder')->rebuild(); $this->moduleHandler->invokeAll('modules_installed', array($modules_installed)); } @@ -356,6 +356,9 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { } } + // @todo: make this a method on the RouteBuilder. + \Drupal::service('cache.default')->delete('routebuilder:yml:' . $module); + // Allow modules to react prior to the uninstallation of a module. $this->moduleHandler->invokeAll('module_preuninstall', array($module)); @@ -400,7 +403,6 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // Clear plugin manager caches and flag router to rebuild if requested. \Drupal::getContainer()->get('plugin.cache_clearer')->clearCachedDefinitions(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); // Update the kernel to exclude the uninstalled modules. $this->updateKernel($module_filenames); @@ -419,6 +421,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { $schema_store = \Drupal::keyValue('system.schema'); $schema_store->delete($module); } + \Drupal::service('router.builder')->rebuild(); drupal_get_installed_schema_version(NULL, TRUE); // Let other modules react. diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 8beb184..8442ccf 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -13,7 +13,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigInstallerInterface; use Drupal\Core\Config\ConfigManagerInterface; -use Drupal\Core\Routing\RouteBuilderIndicatorInterface; +use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\State\StateInterface; use Psr\Log\LoggerInterface; @@ -87,11 +87,11 @@ class ThemeHandler implements ThemeHandlerInterface { protected $logger; /** - * The route builder indicator to rebuild the routes if a theme is installed. + * The route builder to rebuild the routes if a theme is installed. * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface + * @var \Drupal\Core\Routing\RouteBuilderInterface */ - protected $routeBuilderIndicator; + protected $routeBuilder; /** * An extension discovery instance. @@ -144,13 +144,13 @@ class ThemeHandler implements ThemeHandlerInterface { * database. * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager * The config manager used to uninstall a theme. - * @param \Drupal\Core\Routing\RouteBuilderIndicatorInterface $route_builder_indicator - * (optional) The route builder indicator service to rebuild the routes if a + * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder + * (optional) The route builder service to rebuild the routes if a * theme is installed. * @param \Drupal\Core\Extension\ExtensionDiscovery $extension_discovery * (optional) A extension discovery instance (for unit tests). */ - public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderIndicatorInterface $route_builder_indicator = NULL, ExtensionDiscovery $extension_discovery = NULL) { + public function __construct($root, ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, StateInterface $state, InfoParserInterface $info_parser,LoggerInterface $logger, AssetCollectionOptimizerInterface $css_collection_optimizer = NULL, ConfigInstallerInterface $config_installer = NULL, ConfigManagerInterface $config_manager = NULL, RouteBuilderInterface $route_builder = NULL, ExtensionDiscovery $extension_discovery = NULL) { $this->root = $root; $this->configFactory = $config_factory; $this->moduleHandler = $module_handler; @@ -160,7 +160,7 @@ public function __construct($root, ConfigFactoryInterface $config_factory, Modul $this->cssCollectionOptimizer = $css_collection_optimizer; $this->configInstaller = $config_installer; $this->configManager = $config_manager; - $this->routeBuilderIndicator = $route_builder_indicator; + $this->routeBuilder = $route_builder; $this->extensionDiscovery = $extension_discovery; } @@ -614,8 +614,8 @@ protected function getExtensionDiscovery() { * Resets some other systems like rebuilding the route information or caches. */ protected function resetSystem() { - if ($this->routeBuilderIndicator) { - $this->routeBuilderIndicator->setRebuildNeeded(); + if ($this->routeBuilder) { + $this->routeBuilder->rebuild(); } $this->systemListReset(); diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 5b85d7f..cc3e6a1 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -191,7 +191,6 @@ public function getLocalTasksForRoute($route_name) { else { // Maybe some code asked to rebuild the routes, so rebuild the router // as we rely on having proper existing routes in dynamic local tasks. - $this->routeBuilder->rebuildIfNeeded(); $definitions = $this->getDefinitions(); // We build the hierarchy by finding all tabs that should // appear on the current route. diff --git a/core/lib/Drupal/Core/Routing/RouteBuilder.php b/core/lib/Drupal/Core/Routing/RouteBuilder.php index a4b17e2..72ae0db 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Routing; use Drupal\Component\Discovery\YamlDiscovery; +use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Access\CheckProviderInterface; use Drupal\Core\Controller\ControllerResolverInterface; use Drupal\Core\Extension\ModuleHandlerInterface; @@ -58,13 +59,6 @@ class RouteBuilder implements RouteBuilderInterface { protected $moduleHandler; /** - * The route builder indicator. - * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface - */ - protected $routeBuilderIndicator; - - /** * The controller resolver. * * @var \Drupal\Core\Controller\ControllerResolverInterface @@ -107,17 +101,17 @@ class RouteBuilder implements RouteBuilderInterface { * The controller resolver. * @param \Drupal\Core\Access\CheckProviderInterface $check_provider * The check provider. - * @param \Drupal\Core\Routing\RouteBuilderIndicatorInterface $route_build_indicator - * The route build indicator. + * @param \Drupal\Core\Cache\CacheBackendInterface $cache + * The cache object. */ - public function __construct(MatcherDumperInterface $dumper, LockBackendInterface $lock, EventDispatcherInterface $dispatcher, ModuleHandlerInterface $module_handler, ControllerResolverInterface $controller_resolver, CheckProviderInterface $check_provider, RouteBuilderIndicatorInterface $route_build_indicator = NULL) { + public function __construct(MatcherDumperInterface $dumper, LockBackendInterface $lock, EventDispatcherInterface $dispatcher, ModuleHandlerInterface $module_handler, ControllerResolverInterface $controller_resolver, CheckProviderInterface $check_provider, CacheBackendInterface $cache) { $this->dumper = $dumper; $this->lock = $lock; $this->dispatcher = $dispatcher; $this->moduleHandler = $module_handler; $this->controllerResolver = $controller_resolver; - $this->routeBuilderIndicator = $route_build_indicator; $this->checkProvider = $check_provider; + $this->cache = $cache; } /** @@ -176,7 +170,6 @@ public function rebuild() { $route = new Route($route_info['path'], $route_info['defaults'], $route_info['requirements'], $route_info['options']); $collection->add($name, $route); } - } // DYNAMIC is supposed to be used to add new routes based upon all the @@ -193,7 +186,6 @@ public function rebuild() { $this->dumper->addRoutes($collection); $this->dumper->dump(); - $this->routeBuilderIndicator->setRebuildDone(); $this->lock->release('router_rebuild'); $this->dispatcher->dispatch(RoutingEvents::FINISHED, new Event()); $this->building = FALSE; @@ -211,33 +203,43 @@ public function getCollectionDuringRebuild() { } /** - * {@inheritdoc} - */ - public function rebuildIfNeeded() { - if ($this->routeBuilderIndicator->isRebuildNeeded()) { - return $this->rebuild(); - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function setRebuildNeeded() { - $this->routeBuilderIndicator->setRebuildNeeded(); - } - - /** * Retrieves all defined routes from .routing.yml files. * * @return array * The defined routes, keyed by provider. */ protected function getRouteDefinitions() { - if (!isset($this->yamlDiscovery)) { - $this->yamlDiscovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories()); + $route_definitions = []; + $cache_ids = []; + $module_cache_id_map = []; + + $module_dirs = $this->moduleHandler->getModuleDirectories(); + foreach ($module_dirs as $module => $dir) { + $cache_ids[] = 'routebuilder:yml:' . $module; + $module_cache_id_map['routebuilder:yml:' . $module] = $module; + } + foreach ($this->cache->getMultiple($cache_ids) as $cache) { + if ($cache->data) { + $route_definitions[$module_cache_id_map[$cache->cid]] = $cache->data; + } + unset($module_dirs[$module_cache_id_map[$cache->cid]]); + } + if ($module_dirs) { + if (!isset($this->yamlDiscovery)) { + $this->yamlDiscovery = new YamlDiscovery('routing', $module_dirs); + } + foreach ($this->yamlDiscovery->findAll() as $module => $routes) { + $route_definitions[$module] = $routes; + $this->cache->set('routebuilder:yml:' . $module, $routes); + unset($module_dirs[$module]); + } + // Cache the fact that this module has no routing yml to parse. + foreach ($module_dirs as $module) { + $routes = []; + $this->cache->set('routebuilder:yml:' . $module, $routes); + } } - return $this->yamlDiscovery->findAll(); + return $route_definitions; } } diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php deleted file mode 100644 index 5f06120..0000000 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicator.php +++ /dev/null @@ -1,55 +0,0 @@ -state = $state; - } - - /** - * {@inheritdoc} - */ - public function setRebuildNeeded() { - $this->state->set(static::REBUILD_NEEDED, TRUE); - } - - /** - * {@inheritdoc} - */ - public function isRebuildNeeded() { - return $this->state->get(static::REBUILD_NEEDED, FALSE); - } - - /** - * {@inheritdoc} - */ - public function setRebuildDone() { - $this->state->set(static::REBUILD_NEEDED, FALSE); - } - -} diff --git a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php b/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php deleted file mode 100644 index 68ce5b8..0000000 --- a/core/lib/Drupal/Core/Routing/RouteBuilderIndicatorInterface.php +++ /dev/null @@ -1,39 +0,0 @@ -rebuildNeeded && $this->rebuild()) { - $this->rebuildNeeded = FALSE; - return TRUE; - } - return FALSE; - } - - /** - * {@inheritdoc} - */ - public function setRebuildNeeded() { - $this->rebuildNeeded = TRUE; - } - public function getCollectionDuringRebuild() { return FALSE; } diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index da9dc1b..767b03b 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -121,14 +121,7 @@ public function getRouteCollectionForRequest(Request $request) { $path = rtrim($request->getPathInfo(), '/'); } - $collection = $this->getRoutesByPath($path); - - // Try rebuilding the router if it is necessary. - if (!$collection->count() && $this->routeBuilder->rebuildIfNeeded()) { - $collection = $this->getRoutesByPath($path); - } - - return $collection; + return $this->getRoutesByPath($path); } /** @@ -174,8 +167,6 @@ public function getRoutesByNames($names) { throw new \InvalidArgumentException('You must specify the route names to load'); } - $this->routeBuilder->rebuildIfNeeded(); - $routes_to_load = array_diff($names, array_keys($this->routes)); if ($routes_to_load) { $result = $this->connection->query('SELECT name, route FROM {' . $this->connection->escapeTable($this->tableName) . '} WHERE name IN (:names)', array(':names' => $routes_to_load)); @@ -261,8 +252,6 @@ public function getCandidateOutlines(array $parts) { */ public function getRoutesByPattern($pattern) { $path = RouteCompiler::getPatternOutline($pattern); - $this->routeBuilder->rebuildIfNeeded(); - return $this->getRoutesByPath($path); } diff --git a/core/modules/block/src/Tests/BlockHiddenRegionTest.php b/core/modules/block/src/Tests/BlockHiddenRegionTest.php index f451103..b06e656 100644 --- a/core/modules/block/src/Tests/BlockHiddenRegionTest.php +++ b/core/modules/block/src/Tests/BlockHiddenRegionTest.php @@ -61,7 +61,7 @@ public function testBlockNotInHiddenRegion() { ->save(); // Installing a theme will cause the kernel terminate event to rebuild the // router. Simulate that here. - \Drupal::service('router.builder')->rebuildIfNeeded(); + \Drupal::service('router.builder')->rebuild(); // Ensure that "block_test_theme" is set as the default theme. $this->drupalGet('admin/structure/block'); diff --git a/core/modules/book/src/Tests/BookUninstallTest.php b/core/modules/book/src/Tests/BookUninstallTest.php index a1d55f7..39295fe 100644 --- a/core/modules/book/src/Tests/BookUninstallTest.php +++ b/core/modules/book/src/Tests/BookUninstallTest.php @@ -30,6 +30,7 @@ class BookUninstallTest extends KernelTestBase { */ protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installSchema('book', array('book')); diff --git a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php index a8a46f9..0e5cf08 100644 --- a/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php +++ b/core/modules/breakpoint/src/Tests/BreakpointDiscoveryTest.php @@ -20,10 +20,11 @@ class BreakpointDiscoveryTest extends KernelTestBase { * * @var array */ - public static $modules = array('breakpoint', 'breakpoint_module_test'); + public static $modules = array('system', 'breakpoint', 'breakpoint_module_test'); protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); \Drupal::service('theme_handler')->install(array('breakpoint_theme_test')); } diff --git a/core/modules/ckeditor/src/Tests/CKEditorTest.php b/core/modules/ckeditor/src/Tests/CKEditorTest.php index 9133ee0..c854586 100644 --- a/core/modules/ckeditor/src/Tests/CKEditorTest.php +++ b/core/modules/ckeditor/src/Tests/CKEditorTest.php @@ -44,6 +44,7 @@ protected function setUp() { // Install the Filter module. $this->installSchema('system', 'url_alias'); + $this->installSchema('system', 'router'); // Create text format, associate CKEditor. $filtered_html_format = entity_create('filter_format', array( diff --git a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php index 3cb8ab0..ddfaf8f 100644 --- a/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php +++ b/core/modules/comment/src/Tests/CommentStringIdEntitiesTest.php @@ -29,6 +29,7 @@ class CommentStringIdEntitiesTest extends KernelTestBase { 'field_ui', 'entity', 'entity_test', + 'system', 'text', ); @@ -36,6 +37,7 @@ protected function setUp() { parent::setUp(); $this->installEntitySchema('comment'); $this->installSchema('comment', array('comment_entity_statistics')); + $this->installSchema('system', array('router')); // Create the comment body field storage. $this->installConfig(array('field')); } diff --git a/core/modules/config/src/Tests/ConfigCRUDTest.php b/core/modules/config/src/Tests/ConfigCRUDTest.php index 4c3642e..63802cb 100644 --- a/core/modules/config/src/Tests/ConfigCRUDTest.php +++ b/core/modules/config/src/Tests/ConfigCRUDTest.php @@ -39,6 +39,11 @@ class ConfigCRUDTest extends KernelTestBase { */ public static $modules = array('system'); + protected function setUp() { + parent::setUp(); + $this->installSchema('system', 'router'); + } + /** * Tests CRUD operations. */ diff --git a/core/modules/config/src/Tests/DefaultConfigTest.php b/core/modules/config/src/Tests/DefaultConfigTest.php index 99ff07a..2d5412c 100644 --- a/core/modules/config/src/Tests/DefaultConfigTest.php +++ b/core/modules/config/src/Tests/DefaultConfigTest.php @@ -45,6 +45,7 @@ class DefaultConfigTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installSchema('system', 'router'); \Drupal::service('theme_handler')->install($this->themes); } diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index d812652..44224d9 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -337,5 +337,5 @@ function content_translation_form_language_content_settings_submit(array $form, // Ensure entity and menu router information are correctly rebuilt. \Drupal::entityManager()->clearCachedDefinitions(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index da196a5..ac41f8e 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -610,7 +610,7 @@ function content_translation_language_configuration_element_submit(array $form, if (\Drupal::service('content_translation.manager')->isEnabled($context['entity_type'], $context['bundle']) != $enabled) { \Drupal::service('content_translation.manager')->setEnabled($context['entity_type'], $context['bundle'], $enabled); \Drupal::entityManager()->clearCachedDefinitions(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } } diff --git a/core/modules/field/src/Tests/FieldUnitTestBase.php b/core/modules/field/src/Tests/FieldUnitTestBase.php index 0b0895f..3c2b535 100644 --- a/core/modules/field/src/Tests/FieldUnitTestBase.php +++ b/core/modules/field/src/Tests/FieldUnitTestBase.php @@ -51,6 +51,7 @@ protected function setUp() { $this->installEntitySchema('entity_test'); $this->installEntitySchema('user'); $this->installSchema('system', array('sequences')); + $this->installSchema('system', array('router')); // Set default storage backend and configure the theme system. $this->installConfig(array('field', 'system')); diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index bdd492a..2a8fabd 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -105,7 +105,7 @@ function field_ui_entity_type_build(array &$entity_types) { function field_ui_entity_bundle_create($entity_type, $bundle) { // When a new bundle is created, the menu needs to be rebuilt to add our // menu item tabs. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** @@ -114,7 +114,7 @@ function field_ui_entity_bundle_create($entity_type, $bundle) { function field_ui_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) { // When a bundle is renamed, the menu needs to be rebuilt to add our // menu item tabs. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** @@ -189,14 +189,14 @@ function field_ui_form_node_type_form_submit($form, FormStateInterface $form_sta * Implements hook_view_mode_presave(). */ function field_ui_view_mode_presave(EntityViewModeInterface $view_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** * Implements hook_view_mode_delete(). */ function field_ui_view_mode_delete(EntityViewModeInterface $view_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index 2f47234..ad72327 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -21,6 +21,7 @@ class EntityDisplayTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); $this->installEntitySchema('node'); $this->installConfig(array('field')); } diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php index 2808fc1..e295b41 100644 --- a/core/modules/filter/src/Tests/FilterAPITest.php +++ b/core/modules/filter/src/Tests/FilterAPITest.php @@ -28,6 +28,7 @@ class FilterAPITest extends EntityUnitTestBase { protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); $this->installConfig(array('system', 'filter')); } diff --git a/core/modules/menu_ui/menu_ui.install b/core/modules/menu_ui/menu_ui.install index c2aadce..3fdc060 100644 --- a/core/modules/menu_ui/menu_ui.install +++ b/core/modules/menu_ui/menu_ui.install @@ -21,5 +21,5 @@ function menu_ui_install() { * Implements hook_uninstall(). */ function menu_ui_uninstall() { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 918e738..909b45f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -917,7 +917,7 @@ function node_form_system_themes_admin_form_submit($form, FormStateInterface $fo \Drupal::config('node.settings') ->set('use_admin_theme', $form_state->getValue('use_admin_theme')) ->save(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** diff --git a/core/modules/node/src/Tests/Config/NodeImportCreateTest.php b/core/modules/node/src/Tests/Config/NodeImportCreateTest.php index 99f4e56..c72fa8e 100644 --- a/core/modules/node/src/Tests/Config/NodeImportCreateTest.php +++ b/core/modules/node/src/Tests/Config/NodeImportCreateTest.php @@ -29,6 +29,7 @@ class NodeImportCreateTest extends KernelTestBase { */ protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); $this->installEntitySchema('user'); // Set default storage backend. diff --git a/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php b/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php index bdfa24c..6e606f5 100644 --- a/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php +++ b/core/modules/node/src/Tests/NodeBodyFieldStorageTest.php @@ -32,6 +32,7 @@ class NodeBodyFieldStorageTest extends KernelTestBase { protected function setUp() { parent::setUp(); $this->installSchema('system', 'sequences'); + $this->installSchema('system', array('router')); // Necessary for module uninstall. $this->installSchema('user', 'users_data'); $this->installEntitySchema('user'); diff --git a/core/modules/search/src/Entity/SearchPage.php b/core/modules/search/src/Entity/SearchPage.php index c2d0794..e11f76d 100644 --- a/core/modules/search/src/Entity/SearchPage.php +++ b/core/modules/search/src/Entity/SearchPage.php @@ -184,7 +184,7 @@ public function postCreate(EntityStorageInterface $storage) { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { parent::postSave($storage, $update); - $this->routeBuilderIndicator()->setRebuildNeeded(); + $this->routeBuilder()->rebuild(); } /** @@ -216,11 +216,11 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) /** * Wraps the route builder. * - * @return \Drupal\Core\Routing\RouteBuilderIndicatorInterface + * @return \Drupal\Core\Routing\RouteBuilderInterface * An object for state storage. */ - protected function routeBuilderIndicator() { - return \Drupal::service('router.builder_indicator'); + protected function routeBuilder() { + return \Drupal::service('router.builder'); } /** diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php index d029073..c60e7a1 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -172,7 +172,7 @@ public function testShortcutLinkChangeRoute() { entity_load('view', 'content')->disable()->save(); /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */ $router_builder = \Drupal::service('router.builder'); - $router_builder->rebuildIfNeeded(); + $router_builder->rebuild(); $this->drupalGet('admin/content'); $this->assertResponse(200); } diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 62612dd..1e482b9 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -21,7 +21,7 @@ class KernelTestBaseTest extends KernelTestBase { * * @var array */ - public static $modules = array('entity_test'); + public static $modules = array('entity_test', 'system'); /** * {@inheritdoc} diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 189e8a2..ed56d4e 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -724,7 +724,7 @@ function hook_entity_bundle_info_alter(&$bundles) { function hook_entity_bundle_create($entity_type_id, $bundle) { // When a new bundle is created, the menu needs to be rebuilt to add the // Field UI menu item tabs. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** diff --git a/core/modules/system/src/Controller/ThemeController.php b/core/modules/system/src/Controller/ThemeController.php index 3bb6d31..e997324 100644 --- a/core/modules/system/src/Controller/ThemeController.php +++ b/core/modules/system/src/Controller/ThemeController.php @@ -8,8 +8,8 @@ namespace Drupal\system\Controller; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\Extension\ThemeHandlerInterface; -use Drupal\Core\Routing\RouteBuilderIndicatorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -29,21 +29,21 @@ class ThemeController extends ControllerBase { /** * The route builder service. * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface + * @var \Drupal\Core\Routing\RouteBuilderInterface */ - protected $routeBuilderIndicator; + protected $routeBuilder; /** * Constructs a new ThemeController. * * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler * The theme handler. - * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder_indicator + * @param \Drupal\Core\Routing\RouteBuilderInterface $route_builder * The route builder. */ - public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderIndicatorInterface $route_builder_indicator) { + public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderInterface $route_builder) { $this->themeHandler = $theme_handler; - $this->routeBuilderIndicator = $route_builder_indicator; + $this->routeBuilder = $route_builder; } /** @@ -52,7 +52,7 @@ public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderIn public static function create(ContainerInterface $container) { return new static( $container->get('theme_handler'), - $container->get('router.builder_indicator') + $container->get('router.builder') ); } @@ -157,7 +157,7 @@ public function setDefaultTheme(Request $request) { // Set the default theme. $config->set('default', $theme)->save(); - $this->routeBuilderIndicator->setRebuildNeeded(); + $this->routeBuilder->rebuild(); // The status message depends on whether an admin theme is currently in // use: a value of 0 means the admin theme is set to be the default diff --git a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php index bef6889..9dd0c23 100644 --- a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php +++ b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php @@ -22,6 +22,11 @@ class CurrentThemeConditionTest extends KernelTestBase { */ public static $modules = array('system', 'theme_test'); + protected function setUp() { + parent::setUp(); + $this->installSchema('system', array('router')); + } + /** * Tests the current theme condition. */ diff --git a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php index 2a34c20..af8f58d 100644 --- a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php +++ b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php @@ -16,6 +16,11 @@ */ class ModuleImplementsAlterTest extends KernelTestBase { + protected function setUp() { + parent::setUp(); + $this->installSchema('system', array('router')); + } + /** * Tests hook_module_implements_alter() adding an implementation. * diff --git a/core/modules/system/src/Tests/System/InfoAlterTest.php b/core/modules/system/src/Tests/System/InfoAlterTest.php index 02cdd17..a96c492 100644 --- a/core/modules/system/src/Tests/System/InfoAlterTest.php +++ b/core/modules/system/src/Tests/System/InfoAlterTest.php @@ -18,6 +18,11 @@ class InfoAlterTest extends KernelTestBase { public static $modules = array('system'); + protected function setUp() { + parent::setUp(); + $this->installSchema('system', array('router')); + } + /** * Tests that theme .info.yml data is rebuild after enabling a module. * diff --git a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php index 3ef48d0..09d73e7 100644 --- a/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeSettingsTest.php @@ -34,6 +34,7 @@ class ThemeSettingsTest extends KernelTestBase { protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router')); // Theme settings rely on System module's system.theme.global configuration. $this->installConfig(array('system')); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index a02d098..f78dc00 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1368,7 +1368,7 @@ function user_modules_installed($modules) { if ($rid) { // Some permissions call the url generator, so ensure that the routes are // up to date. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); /** @var \Drupal\user\PermissionHandlerInterface $permission_handler */ $permission_handler = \Drupal::service('user.permissions'); $permissions = $permission_handler->getPermissions(); diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index f0d10ea..851402c 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -368,9 +368,9 @@ public function postSave(EntityStorageInterface $storage, $update = TRUE) { // @todo Remove if views implements a view_builder controller. views_invalidate_cache(); - // Rebuild the router case the view got enabled. + // Rebuild the router if this is a new view, or it's status changed. if (!isset($this->original) || ($this->status() != $this->original->status())) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } } diff --git a/core/modules/views/src/Tests/Plugin/AccessTest.php b/core/modules/views/src/Tests/Plugin/AccessTest.php index 0bdec9e..4a2b315 100644 --- a/core/modules/views/src/Tests/Plugin/AccessTest.php +++ b/core/modules/views/src/Tests/Plugin/AccessTest.php @@ -87,7 +87,7 @@ function testStaticAccessPlugin() { $view->save(); // Saving a view will cause the router to be rebuilt when the kernel // termination event fires. Simulate that here. - $this->container->get('router.builder')->rebuildIfNeeded(); + $this->container->get('router.builder')->rebuild(); $this->assertTrue($access_plugin->access($this->normal_user)); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index 7f5ebe4..675069b 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -80,7 +80,7 @@ public function testPageResponses() { $view->storage->disable()->save(); // Router rebuild would occur in a kernel terminate event so we need to // simulate that here. - \Drupal::service('router.builder')->rebuildIfNeeded(); + \Drupal::service('router.builder')->rebuild(); $response = $this->container->get('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST); $this->assertEqual($response->getStatusCode(), 404); diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php index 3c52272..c54063d 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php @@ -247,7 +247,7 @@ public function testInvalidDisplayPlugins() { // Rebuild the router, and ensure that the path is not accessible anymore. views_invalidate_cache(); - \Drupal::service('router.builder')->rebuildIfNeeded(); + \Drupal::service('router.builder')->rebuild(); $this->drupalGet('test_display_invalid'); $this->assertResponse(404); diff --git a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php index 9f45e8d..17e074c 100644 --- a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php @@ -39,6 +39,7 @@ protected function setUpFixtures() { // Create a record for uid 1. $this->installSchema('system', 'sequences'); + $this->installSchema('system', 'router'); $this->root_user = entity_create('user', array('name' => $this->randomMachineName())); $this->root_user->save(); diff --git a/core/modules/views/src/Tests/ViewUnitTestBase.php b/core/modules/views/src/Tests/ViewUnitTestBase.php index 0d07484..9486a48 100644 --- a/core/modules/views/src/Tests/ViewUnitTestBase.php +++ b/core/modules/views/src/Tests/ViewUnitTestBase.php @@ -48,13 +48,14 @@ protected function setUpFixtures() { \Drupal::state()->set('views_test_data_schema', $this->schemaDefinition()); \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); + // The router table is required for router rebuilds. + $this->installSchema('system', array('router')); + $this->installConfig(array('views', 'views_test_config', 'views_test_data')); foreach ($this->schemaDefinition() as $table => $schema) { $this->installSchema('views_test_data', $table); } - // The router table is required for router rebuilds. - $this->installSchema('system', array('router')); \Drupal::service('router.builder')->rebuild(); // Load the test dataset. diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 7c170dc..707ad1f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -492,7 +492,7 @@ function views_invalidate_cache() { Cache::deleteTags(array('extension' => 'views')); // Set the menu as needed to be rebuilt. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); $module_handler = \Drupal::moduleHandler(); diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 0a58e81..3391646 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -22,11 +22,11 @@ class ThemeHandlerTest extends UnitTestCase { /** - * The mocked route builder indicator. + * The mocked route builder. * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Routing\RouteBuilderInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $routeBuilderIndicator; + protected $routeBuilder; /** * The mocked info parser. @@ -111,7 +111,7 @@ protected function setUp() { $this->infoParser = $this->getMock('Drupal\Core\Extension\InfoParserInterface'); $this->configInstaller = $this->getMock('Drupal\Core\Config\ConfigInstallerInterface'); $this->configManager = $this->getMock('Drupal\Core\Config\ConfigManagerInterface'); - $this->routeBuilderIndicator = $this->getMock('Drupal\Core\Routing\RouteBuilderIndicatorInterface'); + $this->routeBuilder = $this->getMock('Drupal\Core\Routing\RouteBuilderInterface'); $this->extensionDiscovery = $this->getMockBuilder('Drupal\Core\Extension\ExtensionDiscovery') ->disableOriginalConstructor() ->getMock(); @@ -119,7 +119,7 @@ protected function setUp() { ->disableOriginalConstructor() ->getMock(); $logger = $this->getMock('Psr\Log\LoggerInterface'); - $this->themeHandler = new TestThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilderIndicator, $this->extensionDiscovery); + $this->themeHandler = new TestThemeHandler($this->root, $this->configFactory, $this->moduleHandler, $this->state, $this->infoParser, $logger, $this->cssCollectionOptimizer, $this->configInstaller, $this->configManager, $this->routeBuilder, $this->extensionDiscovery); $cache_backend = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->getContainerWithCacheBins($cache_backend); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 4c3718b..271ff6c 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -179,9 +179,6 @@ public function testGetLocalTaskForRouteWithEmptyCache() { ->method('set') ->with('local_task_plugins:en', $definitions, Cache::PERMANENT); - $this->routeBuilder->expects($this->once()) - ->method('rebuildIfNeeded'); - $expected_set = $this->getLocalTasksCache(); $this->cacheBackend->expects($this->at(3)) @@ -215,7 +212,7 @@ public function testGetLocalTaskForRouteWithFilledCache() { ->method('set'); $this->routeBuilder->expects($this->never()) - ->method('rebuildIfNeeded'); + ->method('rebuild'); $result = $this->getLocalTasksForRouteResult($mock_plugin); $local_tasks = $this->manager->getLocalTasksForRoute('menu_local_task_test_tasks_view'); diff --git a/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php b/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php index 55c00c8..9db7e45 100644 --- a/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php +++ b/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php @@ -9,12 +9,6 @@ class NullRouteBuilder implements RouteBuilderInterface { public function rebuild() { } - public function rebuildIfNeeded() { - } - - public function setRebuildNeeded() { - } - public function getCollectionDuringRebuild() { return FALSE; } diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php index b0efe77..995d678 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php @@ -72,11 +72,11 @@ class RouteBuilderTest extends UnitTestCase { protected $controllerResolver; /** - * The key value store. + * The cache object for our RouteBuilder. * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $routeBuilderIndicator; + protected $cache; /** * @var \Drupal\Core\Access\CheckProviderInterface|\PHPUnit_Framework_MockObject_MockObject @@ -87,15 +87,15 @@ protected function setUp() { $this->dumper = $this->getMock('Drupal\Core\Routing\MatcherDumperInterface'); $this->lock = $this->getMock('Drupal\Core\Lock\LockBackendInterface'); $this->dispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface'); + $this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface'); $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->controllerResolver = $this->getMock('Drupal\Core\Controller\ControllerResolverInterface'); $this->yamlDiscovery = $this->getMockBuilder('\Drupal\Component\Discovery\YamlDiscovery') ->disableOriginalConstructor() ->getMock(); - $this->routeBuilderIndicator = $this->getMock('\Drupal\Core\Routing\RouteBuilderIndicatorInterface'); $this->checkProvider = $this->getMock('\Drupal\Core\Access\CheckProviderInterface'); - $this->routeBuilder = new TestRouteBuilder($this->dumper, $this->lock, $this->dispatcher, $this->moduleHandler, $this->controllerResolver, $this->checkProvider, $this->routeBuilderIndicator); + $this->routeBuilder = new TestRouteBuilder($this->dumper, $this->lock, $this->dispatcher, $this->moduleHandler, $this->controllerResolver, $this->checkProvider, $this->cache); $this->routeBuilder->setYamlDiscovery($this->yamlDiscovery); } @@ -112,8 +112,13 @@ public function testRebuildLockingUnlocking() { ->method('release') ->with('router_rebuild'); - $this->routeBuilderIndicator->expects($this->once()) - ->method('setRebuildDone'); + $this->moduleHandler->expects($this->once()) + ->method('getModuleDirectories') + ->will($this->returnValue(array())); + + $this->cache->expects($this->once()) + ->method('getMultiple') + ->will($this->returnValue(array())); $this->yamlDiscovery->expects($this->any()) ->method('findAll') @@ -162,6 +167,14 @@ public function testRebuildWithStaticModuleRoutes() { ->method('findAll') ->will($this->returnValue(array('test_module' => $routes))); + $this->moduleHandler->expects($this->once()) + ->method('getModuleDirectories') + ->will($this->returnValue(array('test_module' => 'some/dir'))); + + $this->cache->expects($this->once()) + ->method('getMultiple') + ->will($this->returnValue(array())); + $route_collection = $routing_fixtures->sampleRouteCollection(); $route_build_event = new RouteBuildEvent($route_collection); @@ -235,6 +248,14 @@ public function testRebuildWithProviderBasedRoutes() { $route_build_event = new RouteBuildEvent($route_collection_filled); + $this->moduleHandler->expects($this->once()) + ->method('getModuleDirectories') + ->will($this->returnValue(array('test_module' => 'some/dir'))); + + $this->cache->expects($this->once()) + ->method('getMultiple') + ->will($this->returnValue(array())); + // Ensure that the alter routes events are fired. $this->dispatcher->expects($this->at(0)) ->method('dispatch') @@ -259,41 +280,6 @@ public function testRebuildWithProviderBasedRoutes() { $this->assertTrue($this->routeBuilder->rebuild()); } - /** - * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. - */ - public function testRebuildIfNecessary() { - $this->lock->expects($this->once()) - ->method('acquire') - ->with('router_rebuild') - ->will($this->returnValue(TRUE)); - - $this->lock->expects($this->once()) - ->method('release') - ->with('router_rebuild'); - - $this->routeBuilderIndicator->expects($this->once()) - ->method('setRebuildNeeded'); - - $this->routeBuilderIndicator->expects($this->once()) - ->method('setRebuildDone'); - - $this->routeBuilderIndicator->expects($this->exactly(2)) - ->method('isRebuildNeeded') - ->will($this->onConsecutiveCalls(TRUE, FALSE)); - - $this->yamlDiscovery->expects($this->any()) - ->method('findAll') - ->will($this->returnValue(array())); - - $this->routeBuilder->setRebuildNeeded(); - - // This will trigger a successful rebuild. - $this->assertTrue($this->routeBuilder->rebuildIfNeeded()); - - // This will not trigger a rebuild. - $this->assertFalse($this->routeBuilder->rebuildIfNeeded()); - } } /**