diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index f9500a5fc7d..10fabd412aa 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -136,6 +136,10 @@ class ModuleInstaller implements ModuleInstallerInterface { throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters'); } + // Load a new config object for each iteration, otherwise changes made + // in hook_install() are not reflected in $extension_config. + $extension_config = \Drupal::configFactory()->getEditable('core.extension'); + // Check the validity of the default configuration. This will throw // exceptions if the configuration is not valid. $config_installer->checkConfigurationToInstall('module', $module); diff --git a/core/modules/system/tests/modules/module_handler_test_multiple/module_handler_test_multiple.install b/core/modules/system/tests/modules/module_handler_test_multiple/module_handler_test_multiple.install new file mode 100644 index 00000000000..4d992d4c387 --- /dev/null +++ b/core/modules/system/tests/modules/module_handler_test_multiple/module_handler_test_multiple.install @@ -0,0 +1,14 @@ +container->get('router.route_provider')->getRouteByName('router_test.1'); } + /** + * Tests config changes by hook_install() are saved for dependent modules. + * + * @covers ::install + */ + public function testConfigChangeOnInstall() { + // Install the child module so the parent is installed automatically. + $this->container->get('module_installer')->install(['module_handler_test_multiple_child']); + $modules = $this->config('core.extension')->get('module'); + + $this->assertArrayHasKey('module_handler_test_multiple', $modules, 'Module module_handler_test_multiple is installed'); + $this->assertArrayHasKey('module_handler_test_multiple_child', $modules, 'Module module_handler_test_multiple_child is installed'); + $this->assertEquals(1, $modules['module_handler_test_multiple'], 'Weight of module_handler_test_multiple is set.'); + $this->assertEquals(1, $modules['module_handler_test_multiple_child'], 'Weight of module_handler_test_multiple_child is set.'); + } + }