diff --git a/core/core.services.yml b/core/core.services.yml index 2d00da1..5419d85 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -343,7 +343,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'] @@ -632,17 +632,11 @@ 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'] + arguments: ['@router.dumper', '@lock', '@event_dispatcher', '@module_handler', '@controller_resolver', '@access_manager.check_provider', '@cache.default'] tags: - - { name: event_subscriber } + - { name: needs_destruction } 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 57cc618..de44113 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/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index dba7a94..0048ebc 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -222,7 +222,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. @@ -296,6 +295,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)); } @@ -419,7 +419,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); @@ -438,6 +437,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 9529c8a..831a9af 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -14,7 +14,7 @@ use Drupal\Core\Config\ConfigInstallerInterface; use Drupal\Core\Config\ConfigManagerInterface; use Drupal\Core\Config\PreExistingConfigException; -use Drupal\Core\Routing\RouteBuilderIndicatorInterface; +use Drupal\Core\Routing\RouteBuilderInterface; use Drupal\Core\State\StateInterface; use Psr\Log\LoggerInterface; @@ -88,11 +88,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. @@ -145,13 +145,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 - * theme is installed. + * @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; @@ -161,7 +161,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; } @@ -623,8 +623,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->setRebuildNeeded(); } $this->systemListReset(); diff --git a/core/lib/Drupal/Core/Menu/LocalTaskManager.php b/core/lib/Drupal/Core/Menu/LocalTaskManager.php index 997c6db..2ef5de1 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskManager.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskManager.php @@ -201,9 +201,6 @@ public function getLocalTasksForRoute($route_name) { $children = $cache->data['children']; } 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 433abec..23f93c7 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -8,10 +8,12 @@ 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; use Drupal\Core\Lock\LockBackendInterface; +use Drupal\Core\DestructableInterface; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Routing\RouteCollection; @@ -20,7 +22,7 @@ /** * Managing class for rebuilding the router table. */ -class RouteBuilder implements RouteBuilderInterface { +class RouteBuilder implements RouteBuilderInterface, DestructableInterface { /** * The dumper to which we should send collected routes. @@ -58,13 +60,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 @@ -86,6 +81,13 @@ class RouteBuilder implements RouteBuilderInterface { protected $building = FALSE; /** + * Flag that indiciates if we should rebuild at the end of the request. + * + * @var bool + */ + protected $rebuildNeeded = FALSE; + + /** * The check provider. * * @var \Drupal\Core\Access\CheckProviderInterface @@ -107,22 +109,29 @@ 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; } /** * {@inheritdoc} */ +public function setRebuildNeeded() { + $this->rebuildNeeded = TRUE; +} + + /** + * {@inheritdoc} + */ public function rebuild() { if ($this->building) { throw new \RuntimeException('Recursive router rebuild detected.'); @@ -139,8 +148,10 @@ public function rebuild() { $this->building = TRUE; $collection = new RouteCollection(); - $this->routeCollection = $collection; - foreach ($this->getRouteDefinitions() as $routes) { + + $module_dirs = $this->moduleHandler->getModuleDirectories(); + $this->yamlDiscovery = new YamlDiscovery('routing', $module_dirs); + foreach ($this->yamlDiscovery->findAll() as $routes) { // The top-level 'routes_callback' is a list of methods in controller // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods // should return a set of \Symfony\Component\Routing\Route objects, either @@ -176,7 +187,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,12 +203,12 @@ 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; $this->routeCollection = NULL; + $this->rebuildNeeded = FALSE; return TRUE; } @@ -207,7 +217,7 @@ public function rebuild() { * {@inheritdoc} */ public function rebuildIfNeeded() { - if ($this->routeBuilderIndicator->isRebuildNeeded()) { + if ($this->rebuildNeeded) { return $this->rebuild(); } return FALSE; @@ -216,21 +226,10 @@ public function rebuildIfNeeded() { /** * {@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()); + public function destruct() { + if ($this->rebuildNeeded) { + $this->rebuild(); } - return $this->yamlDiscovery->findAll(); } } diff --git a/core/lib/Drupal/Core/Routing/RouteProvider.php b/core/lib/Drupal/Core/Routing/RouteProvider.php index 58e390f..e16dcb7 100644 --- a/core/lib/Drupal/Core/Routing/RouteProvider.php +++ b/core/lib/Drupal/Core/Routing/RouteProvider.php @@ -117,14 +117,7 @@ public function __construct(Connection $connection, RouteBuilderInterface $route public function getRouteCollectionForRequest(Request $request) { $path = $this->currentPath->getPath($request); - $collection = $this->getRoutesByPath(rtrim($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); } /** @@ -170,8 +163,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)); @@ -257,7 +248,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 b5abe7c..df45d4d 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 317a16a..dbd4de5 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 83986eb..e21723a 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 25558d3..ab303b6 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 f42d722..c530b96 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/contact/src/Tests/Views/ContactLinkTest.php b/core/modules/contact/src/Tests/Views/ContactLinkTest.php index bb7fb91..8bc3059 100644 --- a/core/modules/contact/src/Tests/Views/ContactLinkTest.php +++ b/core/modules/contact/src/Tests/Views/ContactLinkTest.php @@ -47,6 +47,7 @@ protected function setUp() { ViewTestData::createTestViews(get_class($this), array('contact_test_views')); + $this->container->get('router.builder')->rebuild(); $this->userData = $this->container->get('user.data'); } diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 341af53..6b87e96 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -295,7 +295,7 @@ 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')->setRebuildNeeded(); // If an entity type is not translatable all its bundles and fields must be // marked as non-translatable. Similarly, if a bundle is made non-translatable diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 8f5e8fd..93d73f9 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -477,7 +477,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')->setRebuildNeeded(); } } diff --git a/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php b/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php index b37666e..033eca3 100644 --- a/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php +++ b/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php @@ -51,6 +51,7 @@ protected function setUp() { $user->save(); ViewTestData::createTestViews(get_class($this), array('content_translation_test_views')); + $this->container->get('router.builder')->rebuild(); } /** diff --git a/core/modules/field/src/Tests/FieldAttachOtherTest.php b/core/modules/field/src/Tests/FieldAttachOtherTest.php index f3b0f67..af92af7 100644 --- a/core/modules/field/src/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/src/Tests/FieldAttachOtherTest.php @@ -20,7 +20,6 @@ class FieldAttachOtherTest extends FieldUnitTestBase { protected function setUp() { parent::setUp(); - $this->installSchema('system', array('router')); $this->container->get('router.builder')->rebuild(); $this->installEntitySchema('entity_test_rev'); $this->createFieldWithStorage(); diff --git a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php index 3e83c4d..08dda90 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php @@ -27,9 +27,9 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase { protected function setUp() { parent::setUp(); // Module uninstall requires the router and users_data tables. + // FieldUnitTestBase already install the router table. // @see drupal_flush_all_caches() // @see user_modules_uninstalled() - $this->installSchema('system', array('router')); $this->installSchema('user', array('users_data')); } 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 64b62ef..24fbf6e 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -80,7 +80,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')->setRebuildNeeded(); } /** @@ -89,7 +89,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')->setRebuildNeeded(); } /** @@ -169,28 +169,28 @@ function field_ui_form_node_type_form_submit($form, FormStateInterface $form_sta * Implements hook_entity_view_mode_presave(). */ function field_ui_entity_view_mode_presave(EntityViewModeInterface $view_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** * Implements hook_entity_form_mode_presave(). */ function field_ui_entity_form_mode_presave(EntityFormModeInterface $form_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->rebuild(); } /** * Implements hook_entity_view_mode_delete(). */ function field_ui_entity_view_mode_delete(EntityViewModeInterface $view_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->setRebuildNeeded(); } /** * Implements hook_entity_form_mode_delete(). */ function field_ui_entity_form_mode_delete(EntityFormModeInterface $form_mode) { - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->setRebuildNeeded(); } /** diff --git a/core/modules/field_ui/src/Tests/EntityDisplayTest.php b/core/modules/field_ui/src/Tests/EntityDisplayTest.php index ef0f476..9cedc2d 100644 --- a/core/modules/field_ui/src/Tests/EntityDisplayTest.php +++ b/core/modules/field_ui/src/Tests/EntityDisplayTest.php @@ -26,6 +26,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 50210b5..75818c2 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/link/src/Tests/LinkItemTest.php b/core/modules/link/src/Tests/LinkItemTest.php index 017c83e..b39d4be 100644 --- a/core/modules/link/src/Tests/LinkItemTest.php +++ b/core/modules/link/src/Tests/LinkItemTest.php @@ -28,7 +28,6 @@ class LinkItemTest extends FieldUnitTestBase { protected function setUp() { parent::setUp(); - $this->installSchema('system', ['router']); // Create a link field for validation. entity_create('field_storage_config', array( diff --git a/core/modules/menu_ui/menu_ui.install b/core/modules/menu_ui/menu_ui.install index c2aadce..a75a02c 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')->setRebuildNeeded(); } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 94559fa..c3aad11 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -880,7 +880,7 @@ function node_form_system_themes_admin_form_submit($form, FormStateInterface $fo \Drupal::configFactory()->getEditable('node.settings') ->set('use_admin_theme', $form_state->getValue('use_admin_theme')) ->save(); - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->setRebuildNeeded(); } /** 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/node/src/Tests/Views/NodeLanguageTest.php b/core/modules/node/src/Tests/Views/NodeLanguageTest.php index 4ced144..905a727 100644 --- a/core/modules/node/src/Tests/Views/NodeLanguageTest.php +++ b/core/modules/node/src/Tests/Views/NodeLanguageTest.php @@ -89,6 +89,7 @@ protected function setUp() { } $node->save(); } + $this->container->get('router.builder')->rebuild(); $user = $this->drupalCreateUser(array('access content overview', 'access content')); $this->drupalLogin($user); diff --git a/core/modules/node/src/Tests/Views/NodeTestBase.php b/core/modules/node/src/Tests/Views/NodeTestBase.php index 765f257..db61f94 100644 --- a/core/modules/node/src/Tests/Views/NodeTestBase.php +++ b/core/modules/node/src/Tests/Views/NodeTestBase.php @@ -27,6 +27,7 @@ protected function setUp($import_test_views = TRUE) { if ($import_test_views) { ViewTestData::createTestViews(get_class($this), array('node_test_views')); + $this->container->get('router.builder')->rebuild(); } } diff --git a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php index a254a0a..fcfe4f8 100644 --- a/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php +++ b/core/modules/options/src/Tests/OptionsFieldUnitTestBase.php @@ -55,7 +55,6 @@ */ protected function setUp() { parent::setUp(); - $this->installSchema('system', array('router')); $this->container->get('router.builder')->rebuild(); $this->fieldStorageDefinition = array( diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php index adddda1..6161326 100644 --- a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php +++ b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php @@ -63,7 +63,6 @@ protected function setUp() { parent::setUp(); - $this->installSchema('system', array('router')); \Drupal::service('router.builder')->rebuild(); } diff --git a/core/modules/search/src/Entity/SearchPage.php b/core/modules/search/src/Entity/SearchPage.php index d8cfc41..0f583c7 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()->setRebuildNeeded(); } /** @@ -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 a59e5d5..5cb82f4 100644 --- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php @@ -183,7 +183,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 218d0b9..8d2382e 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} @@ -44,6 +44,7 @@ function simpletest_test_stub_settings_function() {} $original_container = $this->originalContainer; parent::setUp(); + $this->installSchema('system', array('router')); $this->assertNotIdentical(\Drupal::getContainer(), $original_container, 'KernelTestBase test creates a new container.'); } @@ -51,7 +52,7 @@ function simpletest_test_stub_settings_function() {} * Tests expected behavior of setUp(). */ function testSetUp() { - $modules = array('entity_test'); + $modules = array('entity_test', 'system'); $table = 'entity_test'; // Verify that specified $modules have been loaded. diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 4a70188..b012ede 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -721,7 +721,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')->setRebuildNeeded(); } /** diff --git a/core/modules/system/src/Controller/ThemeController.php b/core/modules/system/src/Controller/ThemeController.php index 7126a7e..dd5f749 100644 --- a/core/modules/system/src/Controller/ThemeController.php +++ b/core/modules/system/src/Controller/ThemeController.php @@ -11,7 +11,7 @@ use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Extension\ThemeHandlerInterface; -use Drupal\Core\Routing\RouteBuilderIndicatorInterface; +use Drupal\Core\Routing\RouteBuilderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -31,24 +31,24 @@ 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. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. */ - public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderIndicatorInterface $route_builder_indicator, ConfigFactoryInterface $config_factory) { + public function __construct(ThemeHandlerInterface $theme_handler, RouteBuilderInterface $route_builder, ConfigFactoryInterface $config_factory) { $this->themeHandler = $theme_handler; - $this->routeBuilderIndicator = $route_builder_indicator; $this->configFactory = $config_factory; + $this->routeBuilder = $route_builder; } /** @@ -57,7 +57,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'), $container->get('config.factory') ); } @@ -179,7 +179,7 @@ public function setDefaultTheme(Request $request) { // Set the default theme. $config->set('default', $theme)->save(); - $this->routeBuilderIndicator->setRebuildNeeded(); + $this->routeBuilder->setRebuildNeeded(); // 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 60b7281..35eca42 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/Field/FieldModuleUninstallValidatorTest.php b/core/modules/system/src/Tests/Field/FieldModuleUninstallValidatorTest.php index f427ade..ea46747 100644 --- a/core/modules/system/src/Tests/Field/FieldModuleUninstallValidatorTest.php +++ b/core/modules/system/src/Tests/Field/FieldModuleUninstallValidatorTest.php @@ -31,6 +31,7 @@ class FieldModuleUninstallValidatorTest extends EntityUnitTestBase { */ protected function setUp() { parent::setUp(); + $this->installSchema('system', 'router'); $this->installSchema('user', 'users_data'); $this->entityDefinitionUpdateManager = $this->container->get('entity.definition_update_manager'); diff --git a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php index 2a34c20..5a8186d 100644 --- a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php +++ b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php @@ -16,6 +16,13 @@ */ class ModuleImplementsAlterTest extends KernelTestBase { + public static $modules = array('system'); + + 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/RegistryTest.php b/core/modules/system/src/Tests/Theme/RegistryTest.php index 8b6cb0a..0f5e973 100644 --- a/core/modules/system/src/Tests/Theme/RegistryTest.php +++ b/core/modules/system/src/Tests/Theme/RegistryTest.php @@ -23,9 +23,19 @@ class RegistryTest extends KernelTestBase { * * @var array */ - public static $modules = array('theme_test'); + public static $modules = array('theme_test', 'system'); protected $profile = 'testing'; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->installSchema('system', ['router']); + } + /** * Tests the behavior of the theme registry class. */ 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/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php index cfc76bd..d58b2d5 100644 --- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php +++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldFilterTest.php @@ -93,7 +93,7 @@ function setUp() { Views::viewsData()->clear(); ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); - + $this->container->get('router.builder')->rebuild(); } /** diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php index bd55022..9f2e095 100644 --- a/core/modules/user/src/Tests/Views/AccessRoleTest.php +++ b/core/modules/user/src/Tests/Views/AccessRoleTest.php @@ -30,13 +30,14 @@ class AccessRoleTest extends AccessTestBase { * Tests role access plugin. */ function testAccessRole() { - /** @var \Drupal\views\ViewentityInterface $view */ + /** @var \Drupal\views\ViewEntityInterface $view */ $view = \Drupal::entityManager()->getStorage('view')->load('test_access_role'); $display = &$view->getDisplay('default'); $display['display_options']['access']['options']['role'] = array( $this->normalRole => $this->normalRole, ); $view->save(); + $this->container->get('router.builder')->rebuild(); $expected = [ 'config' => ['user.role.' . $this->normalRole], 'module' => ['user'], @@ -69,6 +70,7 @@ function testAccessRole() { 'anonymous' => 'anonymous', ); $view->save(); + $this->container->get('router.builder')->rebuild(); // Ensure that the list of roles is sorted correctly, if the generated role // ID comes before 'anonymous', see https://www.drupal.org/node/2398259. diff --git a/core/modules/user/src/Tests/Views/UserTestBase.php b/core/modules/user/src/Tests/Views/UserTestBase.php index 51017dc..ede4c22 100644 --- a/core/modules/user/src/Tests/Views/UserTestBase.php +++ b/core/modules/user/src/Tests/Views/UserTestBase.php @@ -40,6 +40,7 @@ protected function setUp() { parent::setUp(); ViewTestData::createTestViews(get_class($this), array('user_test_views')); + $this->container->get('router.builder')->rebuild(); $this->users[] = $this->drupalCreateUser(); $this->users[] = user_load(1); diff --git a/core/modules/user/src/Tests/Views/UserUnitTestBase.php b/core/modules/user/src/Tests/Views/UserUnitTestBase.php index 672bae7..433719f 100644 --- a/core/modules/user/src/Tests/Views/UserUnitTestBase.php +++ b/core/modules/user/src/Tests/Views/UserUnitTestBase.php @@ -49,7 +49,6 @@ protected function setUp() { ViewTestData::createTestViews(get_class($this), array('user_test_views')); $this->installEntitySchema('user'); - $this->installSchema('system', 'sequences'); $entity_manager = $this->container->get('entity.manager'); $this->roleStorage = $entity_manager->getStorage('user_role'); diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 8317818..8286b54 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1338,7 +1338,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')->setRebuildNeeded(); /** @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 ecd541e..dfbac27 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -332,9 +332,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')->setRebuildNeeded(); } } diff --git a/core/modules/views/src/Tests/GlossaryTest.php b/core/modules/views/src/Tests/GlossaryTest.php index c9cb84a..cc64fb2 100644 --- a/core/modules/views/src/Tests/GlossaryTest.php +++ b/core/modules/views/src/Tests/GlossaryTest.php @@ -62,6 +62,7 @@ public function testGlossaryView() { // Enable the glossary to be displayed. $view->storage->enable()->save(); + $this->container->get('router.builder')->rebuild(); // Check the actual page response. $this->drupalGet('glossary'); $this->assertResponse(200); diff --git a/core/modules/views/src/Tests/Plugin/AccessTest.php b/core/modules/views/src/Tests/Plugin/AccessTest.php index 4bc77db..3033ac5 100644 --- a/core/modules/views/src/Tests/Plugin/AccessTest.php +++ b/core/modules/views/src/Tests/Plugin/AccessTest.php @@ -53,6 +53,7 @@ protected function setUp() { $this->enableViewsTestModule(); ViewTestData::createTestViews(get_class($this), array('views_test_data')); + $this->container->get('router.builder')->rebuild(); $this->webUser = $this->drupalCreateUser(); @@ -99,7 +100,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->normalUser)); diff --git a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php b/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php index 4cfce8c..b4ad910 100644 --- a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php +++ b/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php @@ -73,6 +73,8 @@ public function testDisabledDisplays() { $this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled'); } + \Drupal::service('router.builder')->rebuild(); + // Check that the originally disabled page_2 display is now enabled. $this->drupalGet('test-disabled-display-2'); $result = $this->xpath('//h1'); @@ -86,6 +88,8 @@ public function testDisabledDisplays() { $this->assertFalse($enabled, 'Display ' . $display_id . ' is now disabled'); } + \Drupal::service('router.builder')->rebuild(); + // Check that the page_1 display still works. $this->drupalGet('test-disabled-display'); $this->assertResponse(200); diff --git a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php index 4222f17..70c78d9 100644 --- a/core/modules/views/src/Tests/Plugin/DisplayPageTest.php +++ b/core/modules/views/src/Tests/Plugin/DisplayPageTest.php @@ -50,6 +50,8 @@ class DisplayPageTest extends ViewUnitTestBase { protected function setUp() { parent::setUp(); + $this->container->get('router.builder')->rebuild(); + // Setup the needed tables in order to make the drupal router working. $this->installSchema('system', array('url_alias')); } @@ -80,7 +82,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 f5053b9..2d1b287 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 83fb1cf..9f45e8d 100644 --- a/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php @@ -25,6 +25,11 @@ public static $modules = array('system', 'user', 'field'); /** + * @var \Drupal\user\Entity\User + */ + protected $root_user; + + /** * Overrides \Drupal\views\Tests\ViewUnitTestBase::setUpFixtures(). */ protected function setUpFixtures() { @@ -34,8 +39,8 @@ protected function setUpFixtures() { // Create a record for uid 1. $this->installSchema('system', 'sequences'); - $root_user = entity_create('user', array('name' => $this->randomMachineName())); - $root_user->save(); + $this->root_user = entity_create('user', array('name' => $this->randomMachineName())); + $this->root_user->save(); Views::viewsData()->clear(); } diff --git a/core/modules/views/src/Tests/ViewTestBase.php b/core/modules/views/src/Tests/ViewTestBase.php index 042c5ce..c14a16b 100644 --- a/core/modules/views/src/Tests/ViewTestBase.php +++ b/core/modules/views/src/Tests/ViewTestBase.php @@ -41,6 +41,7 @@ protected function setUp($import_test_views = TRUE) { } if ($import_test_views) { ViewTestData::createTestViews(get_class($this), array('views_test_config')); + $this->container->get('router.builder')->rebuild(); } } diff --git a/core/modules/views/src/Tests/ViewTestData.php b/core/modules/views/src/Tests/ViewTestData.php index 03c4bae..4b5340e 100644 --- a/core/modules/views/src/Tests/ViewTestData.php +++ b/core/modules/views/src/Tests/ViewTestData.php @@ -56,6 +56,9 @@ public static function createTestViews($class, array $modules) { } } } + + // Rebuild the router once. + \Drupal::service('router.builder')->rebuild(); } /** diff --git a/core/modules/views/src/Tests/ViewUnitTestBase.php b/core/modules/views/src/Tests/ViewUnitTestBase.php index 16b1e38..2de7f2b 100644 --- a/core/modules/views/src/Tests/ViewUnitTestBase.php +++ b/core/modules/views/src/Tests/ViewUnitTestBase.php @@ -36,6 +36,7 @@ protected function setUp() { parent::setUp(); + $this->installSchema('system', array('router', 'sequences')); $this->setUpFixtures(); } @@ -59,8 +60,6 @@ protected function setUpFixtures() { $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 d8516be..3f236f8 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -490,7 +490,7 @@ function views_invalidate_cache() { Cache::invalidateTags(['extension:views']); // Set the menu as needed to be rebuilt. - \Drupal::service('router.builder_indicator')->setRebuildNeeded(); + \Drupal::service('router.builder')->setRebuildNeeded(); $module_handler = \Drupal::moduleHandler(); diff --git a/core/modules/views_ui/src/Tests/DisplayTest.php b/core/modules/views_ui/src/Tests/DisplayTest.php index eca12a4..e9e39f2 100644 --- a/core/modules/views_ui/src/Tests/DisplayTest.php +++ b/core/modules/views_ui/src/Tests/DisplayTest.php @@ -178,6 +178,7 @@ public function testPageContextualLinks() { $this->drupalLogin($this->drupalCreateUser(array('administer views', 'access contextual links'))); $view = entity_load('view', 'test_display'); $view->enable()->save(); + $this->container->get('router.builder')->rebuild(); $this->drupalGet('test-display'); $id = 'entity.view.edit_form:view=test_display:location=page&name=test_display&display_id=page_1'; diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 2c9a015..84d4266 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_tags_invalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface'); $this->getContainerWithCacheTagsInvalidator($cache_tags_invalidator); diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php index 8502d7e..937be5a 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php @@ -187,9 +187,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)) @@ -223,7 +220,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..58cb2af 100644 --- a/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php +++ b/core/tests/Drupal/Tests/Core/Routing/NullRouteBuilder.php @@ -6,17 +6,17 @@ class NullRouteBuilder implements RouteBuilderInterface { - public function rebuild() { - } - - public function rebuildIfNeeded() { + public function setRebuildNeeded() { } - public function setRebuildNeeded() { + public function rebuild() { } public function getCollectionDuringRebuild() { return FALSE; } + public function rebuildIfNeeded() { + } + } diff --git a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php index b0efe77..0b00a7c 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') @@ -258,42 +279,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()); - } } /**