Commit 7d18acfe authored by catch's avatar catch

Issue #2788087 by alexpott, dawehner, shafiqhossain: Drupal 8: You have...

Issue #2788087 by alexpott, dawehner, shafiqhossain: Drupal 8: You have requested a non-existent service "router.route_provider.old"
parent 7f68a3d4
......@@ -309,7 +309,11 @@ public function install(array $module_list, $enable_dependencies = TRUE) {
// If any modules were newly installed, invoke hook_modules_installed().
if (!empty($modules_installed)) {
\Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
// If the container was rebuilt during hook_install() it might not have
// the 'router.route_provider.old' service.
if (\Drupal::hasService('router.route_provider.old')) {
\Drupal::getContainer()->set('router.route_provider', \Drupal::service('router.route_provider.old'));
}
if (!\Drupal::service('router.route_provider.lazy_builder')->hasRebuilt()) {
// Rebuild routes after installing module. This is done here on top of
// \Drupal\Core\Routing\RouteBuilder::destruct to not run into errors on
......
......@@ -34,4 +34,9 @@ function module_test_install() {
'data' => $schema['fields']['data']['type'],
])
->execute();
if (\Drupal::state()->get('module_test_install:rebuild_container')) {
// Ensure that the container can be rebuilt during hook_install(). Doing
// this in hook_install() is bad practice but it should not break anything.
\Drupal::service('kernel')->rebuildContainer();
}
}
......@@ -85,4 +85,13 @@ public function testCacheBinCleanup() {
$this->assertFalse($schema->tableExists($table));
}
/**
* Ensure that rebuilding the container in hook_install() works.
*/
public function testKernelRebuildDuringHookInstall() {
\Drupal::state()->set('module_test_install:rebuild_container', TRUE);
$module_installer = $this->container->get('module_installer');
$this->assertTrue($module_installer->install(['module_test']));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment