diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 10fabd412a..c9ab18cc24 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -194,6 +194,17 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // Update the kernel to include it. $this->updateKernel($module_filenames); + // Replace the route provider service with a version that will rebuild + // if routes used during installation. This ensures that a module's + // routes are available during installation. This has to occur before + // any services that depend on the it are instantiated otherwise those + // services will have the old route provider injected. Note that, since + // the container is rebuilt by updating the kernel, the route provide + // service is the regular one even though we are in a loop and might + // have replaced it before. + \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider')); + \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder')); + // Allow modules to react prior to the installation of a module. $this->moduleHandler->invokeAll('module_preinstall', [$module]); @@ -283,10 +294,6 @@ public function install(array $module_list, $enable_dependencies = TRUE) { // @see https://www.drupal.org/node/2208429 \Drupal::service('theme_handler')->refreshInfo(); - // In order to make uninstalling transactional if anything uses routes. - \Drupal::getContainer()->set('router.route_provider.old', \Drupal::service('router.route_provider')); - \Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.lazy_builder')); - // Allow the module to perform install tasks. $this->moduleHandler->invoke($module, 'install'); diff --git a/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.info.yml b/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.info.yml new file mode 100644 index 0000000000..2e0a859dbd --- /dev/null +++ b/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.info.yml @@ -0,0 +1,6 @@ +name: 'Route provider install test' +description: 'Helps test a bug triggered by the url_generator maintaining a stale route provider.' +type: module +package: Testing +version: VERSION +core: 8.x diff --git a/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.services.yml b/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.services.yml new file mode 100644 index 0000000000..68ff1ac8db --- /dev/null +++ b/core/modules/system/tests/modules/route_provider_install_test/route_provider_install_test.services.yml @@ -0,0 +1,5 @@ +services: + plugin.manager.route_provider_install_test: + class: '\Drupal\route_provider_install_test\PluginManager' + parent: default_plugin_manager + arguments: ['@url_generator'] diff --git a/core/modules/system/tests/modules/route_provider_install_test/src/PluginManager.php b/core/modules/system/tests/modules/route_provider_install_test/src/PluginManager.php new file mode 100644 index 0000000000..34669ee43d --- /dev/null +++ b/core/modules/system/tests/modules/route_provider_install_test/src/PluginManager.php @@ -0,0 +1,36 @@ +toString(); + parent::__construct('Plugin/RouteProviderInstallTest', $namespaces, $module_handler, NULL, PluginID::class); + } + +} diff --git a/core/modules/system/tests/modules/router_test_directory/router_test.install b/core/modules/system/tests/modules/router_test_directory/router_test.install new file mode 100644 index 0000000000..9c433c6769 --- /dev/null +++ b/core/modules/system/tests/modules/router_test_directory/router_test.install @@ -0,0 +1,17 @@ +toString(); +} diff --git a/core/tests/Drupal/FunctionalTests/Routing/RouteProviderInstallTest.php b/core/tests/Drupal/FunctionalTests/Routing/RouteProviderInstallTest.php new file mode 100644 index 0000000000..9503116d3a --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Routing/RouteProviderInstallTest.php @@ -0,0 +1,24 @@ +container->get('module_installer')->install(['router_test']); + } + +}