diff --git a/core/core.services.yml b/core/core.services.yml index cf9082c..3eee8fd 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'] @@ -635,17 +635,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'] 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..784285b 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -220,9 +220,8 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Now install the module's schema if necessary. drupal_install_schema($module); - // Clear plugin manager caches and flag router to rebuild if requested. + // Clear plugin manager caches. \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. @@ -294,8 +293,10 @@ public function install(array $module_list, $enable_dependencies = TRUE) { } } - // If any modules were newly installed, invoke hook_modules_installed(). + // If any modules were newly installed, invoke hook_modules_installed() and + // make sure that new routes are picked up. if (!empty($modules_installed)) { + \Drupal::service('router.builder')->setRebuildNeeded(); $this->moduleHandler->invokeAll('modules_installed', array($modules_installed)); } @@ -417,9 +418,8 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { // its statically cached list. drupal_static_reset('system_rebuild_module_data'); - // Clear plugin manager caches and flag router to rebuild if requested. + // Clear plugin manager caches. \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 +438,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { $schema_store = \Drupal::keyValue('system.schema'); $schema_store->delete($module); } + \Drupal::service('router.builder')->setRebuildNeeded(); 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..0dce99d 100644 --- a/core/lib/Drupal/Core/Routing/RouteBuilder.php +++ b/core/lib/Drupal/Core/Routing/RouteBuilder.php @@ -12,6 +12,7 @@ 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 +21,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. @@ -44,13 +45,6 @@ class RouteBuilder implements RouteBuilderInterface { protected $dispatcher; /** - * The yaml discovery used to find all the .routing.yml files. - * - * @var \Drupal\Component\Discovery\YamlDiscovery - */ - protected $yamlDiscovery; - - /** * The module handler. * * @var \Drupal\Core\Extension\ModuleHandlerInterface @@ -58,13 +52,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 +73,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 +101,26 @@ 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. */ - 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) { $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; } /** * {@inheritdoc} */ + public function setRebuildNeeded() { + $this->rebuildNeeded = TRUE; + } + + /** + * {@inheritdoc} + */ public function rebuild() { if ($this->building) { throw new \RuntimeException('Recursive router rebuild detected.'); @@ -139,7 +137,6 @@ public function rebuild() { $this->building = TRUE; $collection = new RouteCollection(); - $this->routeCollection = $collection; foreach ($this->getRouteDefinitions() as $routes) { // The top-level 'routes_callback' is a list of methods in controller // syntax, see \Drupal\Core\Controller\ControllerResolver. These methods @@ -176,7 +173,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 +189,11 @@ 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 +202,7 @@ public function rebuild() { * {@inheritdoc} */ public function rebuildIfNeeded() { - if ($this->routeBuilderIndicator->isRebuildNeeded()) { + if ($this->rebuildNeeded) { return $this->rebuild(); } return FALSE; @@ -216,8 +211,11 @@ public function rebuildIfNeeded() { /** * {@inheritdoc} */ - public function setRebuildNeeded() { - $this->routeBuilderIndicator->setRebuildNeeded(); + public function destruct() { + // Rebuild routes only once at the end of the request lifecycle to not + // trigger multiple rebuilds and also make the page more responsive for the + // user. + $this->rebuildIfNeeded(); } /** @@ -227,10 +225,8 @@ public function setRebuildNeeded() { * The defined routes, keyed by provider. */ protected function getRouteDefinitions() { - if (!isset($this->yamlDiscovery)) { - $this->yamlDiscovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories()); - } - return $this->yamlDiscovery->findAll(); + $discovery = new YamlDiscovery('routing', $this->moduleHandler->getModuleDirectories()); + return $discovery->findAll(); } } 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 @@ -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(rtrim($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/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/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index fbb3a78..2c55fa9 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/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..d71be2e 100644 --- a/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php +++ b/core/modules/field/src/Tests/FieldImportDeleteUninstallTest.php @@ -29,7 +29,6 @@ protected function setUp() { // Module uninstall requires the router and users_data tables. // @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..5c2e22f 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')->setRebuildNeeded(); } /** * 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')->setRebuildNeeded(); } /** * 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/field_ui/src/Tests/FieldUIRouteTest.php b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php index 6ca3df9..5fd8ec0 100644 --- a/core/modules/field_ui/src/Tests/FieldUIRouteTest.php +++ b/core/modules/field_ui/src/Tests/FieldUIRouteTest.php @@ -80,6 +80,8 @@ public function testFieldUIRoutes() { 'label' => 'Test', 'targetEntityType' => 'user', ))->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); + $edit = array('display_modes_custom[test]' => TRUE); $this->drupalPostForm('admin/config/people/accounts/display', $edit, t('Save')); $this->assertLink('Test'); @@ -91,6 +93,8 @@ public function testFieldUIRoutes() { 'label' => 'Test', 'targetEntityType' => 'user', ))->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); + $edit = array('display_modes_custom[test]' => TRUE); $this->drupalPostForm('admin/config/people/accounts/form-display', $edit, t('Save')); $this->assertLink('Test'); diff --git a/core/modules/filter/src/Tests/FilterAPITest.php b/core/modules/filter/src/Tests/FilterAPITest.php index 6ee11e2..3ceb5eb 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 611ae17..f181df1 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 97fe51f..f6902e39 100644 --- a/core/modules/node/src/Tests/Config/NodeImportCreateTest.php +++ b/core/modules/node/src/Tests/Config/NodeImportCreateTest.php @@ -30,6 +30,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/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/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 dd096ca..5ebaca6 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -722,7 +722,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 f1d1b9e..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\RouteBuilderIndicatorInterface $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..164b1e9 100644 --- a/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php +++ b/core/modules/system/src/Tests/Condition/CurrentThemeConditionTest.php @@ -23,6 +23,14 @@ class CurrentThemeConditionTest extends KernelTestBase { public static $modules = array('system', 'theme_test'); /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installSchema('system', array('router')); + } + + /** * Tests the current theme condition. */ public function testCurrentTheme() { 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..b831830 100644 --- a/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php +++ b/core/modules/system/src/Tests/Module/ModuleImplementsAlterTest.php @@ -16,6 +16,16 @@ */ class ModuleImplementsAlterTest extends KernelTestBase { + public static $modules = array('system'); + + /** + * {@inheritdoc} + */ + 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/Routing/RouterTest.php b/core/modules/system/src/Tests/Routing/RouterTest.php index 85e5e4b..92e9608 100644 --- a/core/modules/system/src/Tests/Routing/RouterTest.php +++ b/core/modules/system/src/Tests/Routing/RouterTest.php @@ -194,6 +194,7 @@ public function testControllerResolutionAjax() { */ public function testRouterUninstallInstall() { \Drupal::service('module_installer')->uninstall(array('router_test')); + \Drupal::service('router.builder')->rebuild(); try { \Drupal::service('router.route_provider')->getRouteByName('router_test.1'); $this->fail('Route was delete on uninstall.'); @@ -203,6 +204,7 @@ public function testRouterUninstallInstall() { } // Install the module again. \Drupal::service('module_installer')->install(array('router_test')); + \Drupal::service('router.builder')->rebuild(); $route = \Drupal::service('router.route_provider')->getRouteByName('router_test.1'); $this->assertNotNull($route, 'Route exists after module installation'); } diff --git a/core/modules/system/src/Tests/System/InfoAlterTest.php b/core/modules/system/src/Tests/System/InfoAlterTest.php index 02cdd17..42f5041 100644 --- a/core/modules/system/src/Tests/System/InfoAlterTest.php +++ b/core/modules/system/src/Tests/System/InfoAlterTest.php @@ -19,6 +19,14 @@ class InfoAlterTest extends KernelTestBase { public static $modules = array('system'); /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installSchema('system', array('router')); + } + + /** * Tests that theme .info.yml data is rebuild after enabling a module. * * Tests that info data is rebuilt after a module that implements diff --git a/core/modules/system/src/Tests/System/TrustedHostsTest.php b/core/modules/system/src/Tests/System/TrustedHostsTest.php index 3719bd1..e54decc 100644 --- a/core/modules/system/src/Tests/System/TrustedHostsTest.php +++ b/core/modules/system/src/Tests/System/TrustedHostsTest.php @@ -69,6 +69,7 @@ public function testStatusPageWithConfiguration() { */ public function testFakeRequests() { $this->container->get('module_installer')->install(['trusted_hosts_test']); + $this->container->get('router.builder')->rebuild(); $host = $this->container->get('request_stack')->getCurrentRequest()->getHost(); $settings['settings']['trusted_host_patterns'] = (object) array( @@ -88,6 +89,7 @@ public function testFakeRequests() { public function testShortcut() { $this->container->get('module_installer')->install(['block', 'shortcut']); $this->rebuildContainer(); + $this->container->get('router.builder')->rebuild(); /** @var \Drupal\Core\Entity\EntityManagerInterface $entity_manager */ $entity_manager = $this->container->get('entity.manager'); 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/tracker/src/Tests/TrackerTest.php b/core/modules/tracker/src/Tests/TrackerTest.php index 3ca1dc4..94e981d 100644 --- a/core/modules/tracker/src/Tests/TrackerTest.php +++ b/core/modules/tracker/src/Tests/TrackerTest.php @@ -347,6 +347,7 @@ function testTrackerCronIndexing() { */ function testTrackerAdminUnpublish() { \Drupal::service('module_installer')->install(array('views')); + \Drupal::service('router.builder')->rebuild(); $admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access')); $this->drupalLogin($admin_user); diff --git a/core/modules/user/src/Tests/UserCancelTest.php b/core/modules/user/src/Tests/UserCancelTest.php index 029a66c..2ef966a 100644 --- a/core/modules/user/src/Tests/UserCancelTest.php +++ b/core/modules/user/src/Tests/UserCancelTest.php @@ -72,6 +72,7 @@ function testUserCancelWithoutPermission() { */ public function testUserCancelChangePermission() { \Drupal::service('module_installer')->install(array('user_form_test')); + \Drupal::service('router.builder')->rebuild(); $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save(); // Create a regular user. @@ -96,6 +97,7 @@ public function testUserCancelChangePermission() { */ function testUserCancelUid1() { \Drupal::service('module_installer')->install(array('views')); + \Drupal::service('router.builder')->rebuild(); // Update uid 1's name and password to we know it. $password = user_password(); $account = array( @@ -453,6 +455,7 @@ function testUserWithoutEmailCancelByAdmin() { */ function testMassUserCancelByAdmin() { \Drupal::service('module_installer')->install(array('views')); + \Drupal::service('router.builder')->rebuild(); $this->config('user.settings')->set('cancel_method', 'user_cancel_reassign')->save(); // Enable account cancellation notification. $this->config('user.settings')->set('notify.status_canceled', TRUE)->save(); diff --git a/core/modules/user/src/Tests/Views/AccessRoleTest.php b/core/modules/user/src/Tests/Views/AccessRoleTest.php index bd55022..f79e86e 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')->rebuildIfNeeded(); $expected = [ 'config' => ['user.role.' . $this->normalRole], 'module' => ['user'], @@ -69,6 +70,7 @@ function testAccessRole() { 'anonymous' => 'anonymous', ); $view->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); // 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/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/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index 63d3ba1..5b5e24b 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 5534009..4a8cb8b 100644 --- a/core/modules/views/src/Tests/GlossaryTest.php +++ b/core/modules/views/src/Tests/GlossaryTest.php @@ -68,6 +68,7 @@ public function testGlossaryView() { // Enable the glossary to be displayed. $view->storage->enable()->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); // Check the actual page response. $this->drupalGet('glossary'); $this->assertResponse(200); diff --git a/core/modules/views/src/Tests/Plugin/CacheTest.php b/core/modules/views/src/Tests/Plugin/CacheTest.php index d730abf..9e2c6c4 100644 --- a/core/modules/views/src/Tests/Plugin/CacheTest.php +++ b/core/modules/views/src/Tests/Plugin/CacheTest.php @@ -253,6 +253,8 @@ public function testCacheOutputOnPage() { ) )); $view->save(); + $this->container->get('router.builder')->rebuildIfNeeded(); + $output_key = $view->getDisplay()->getPlugin('cache')->generateOutputKey(); $this->assertFalse(\Drupal::cache('render')->get($output_key)); diff --git a/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php b/core/modules/views/src/Tests/Plugin/DisabledDisplayTest.php index 4cfce8c..e9052b4 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')->rebuildIfNeeded(); + // 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..373fe5a 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/RelationshipJoinTestBase.php b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php index b85c235..5620c0a 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 $rootUser; + + /** * Overrides \Drupal\views\Tests\ViewUnitTestBase::setUpFixtures(). */ protected function setUpFixtures() { @@ -33,9 +38,8 @@ protected function setUpFixtures() { parent::setUpFixtures(); // Create a record for uid 1. - $this->installSchema('system', 'sequences'); - $root_user = entity_create('user', array('name' => $this->randomMachineName())); - $root_user->save(); + $this->rootUser = entity_create('user', array('name' => $this->randomMachineName())); + $this->rootUser->save(); Views::viewsData()->clear(); } 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 3197622..666d55f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -484,7 +484,7 @@ function views_field_config_delete(FieldConfigInterface $field) { */ function views_invalidate_cache() { // 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..1b4d04c 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')->rebuildIfNeeded(); $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..b8f212f 100644 --- a/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/RouteBuilderTest.php @@ -72,13 +72,6 @@ class RouteBuilderTest extends UnitTestCase { protected $controllerResolver; /** - * The key value store. - * - * @var \Drupal\Core\Routing\RouteBuilderIndicatorInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $routeBuilderIndicator; - - /** * @var \Drupal\Core\Access\CheckProviderInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $checkProvider; @@ -92,10 +85,9 @@ protected function setUp() { $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->routeBuilder->setYamlDiscovery($this->yamlDiscovery); } @@ -112,9 +104,6 @@ public function testRebuildLockingUnlocking() { ->method('release') ->with('router_rebuild'); - $this->routeBuilderIndicator->expects($this->once()) - ->method('setRebuildDone'); - $this->yamlDiscovery->expects($this->any()) ->method('findAll') ->will($this->returnValue(array())); @@ -262,25 +251,15 @@ public function testRebuildWithProviderBasedRoutes() { /** * Tests \Drupal\Core\Routing\RouteBuilder::rebuildIfNeeded() method. */ - public function testRebuildIfNecessary() { + public function testRebuildIfNeeded() { $this->lock->expects($this->once()) - ->method('acquire') - ->with('router_rebuild') - ->will($this->returnValue(TRUE)); + ->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)); + ->method('release') + ->with('router_rebuild'); $this->yamlDiscovery->expects($this->any()) ->method('findAll')