diff --git a/core/includes/config.inc b/core/includes/config.inc index 8e9ce5e..dfe9c2e 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -68,18 +68,19 @@ function ($value) use ($name) { $context = new FreeConfigContext(Drupal::service('event_dispatcher'), Drupal::service('uuid')); $target_storage = Drupal::service('config.storage'); $config_factory->enterContext($context); - foreach ($config_to_install as $name) { + foreach ($config_to_install as $config_name) { // Only import new config. - if ($target_storage->exists($name)) { + if ($target_storage->exists($config_name)) { + drupal_set_message(t('Active configuration with the name %config_name already exists therefore can not install the default configuration with the same name from %extension.', array('%config_name' => $config_name, '%extension' => $name)), 'warning'); continue; } - $new_config = new Config($name, $target_storage, $context); - $data = $source_storage->read($name); + $new_config = new Config($config_name, $target_storage, $context); + $data = $source_storage->read($config_name); if ($data !== FALSE) { $new_config->setData($data); } - if ($entity_type = config_get_entity_type_by_name($name)) { + if ($entity_type = config_get_entity_type_by_name($config_name)) { $entity_manager ->getStorageController($entity_type) ->create($new_config->get()) @@ -90,7 +91,7 @@ function ($value) use ($name) { } // Reset static cache on the config factory. - $config_factory->reset($name); + $config_factory->reset($config_name); } $config_factory->leaveContext(); } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php index 3bb7839..b608a6d 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php @@ -90,6 +90,13 @@ function testIntegrationModuleReinstallation() { $config_entity = \Drupal::config($default_configuration_entity); $this->assertIdentical($config_entity->isNew(), FALSE); $this->assertIdentical($config_entity->get('label'), 'Customized integration config label'); + + // Verify that installing a module with default configuration that already + // exists in active configuration produces a warning. + \Drupal::moduleHandler()->install(array('config_install_fail')); + $messages = drupal_get_messages('warning'); + $expected_message = t('Active configuration with the name %config_name already exists therefore can not install the default configuration with the same name from %extension_name.', array('%config_name' => 'config_test.dynamic.dotted.default', '%extension_name' => 'config_install_fail')); + $this->assertTrue(in_array($expected_message, $messages['warning']), 'Warning message about existing configuration exists.'); } } diff --git a/core/modules/config/tests/config_install_fail/config/config_test.dynamic.dotted.default.yml b/core/modules/config/tests/config_install_fail/config/config_test.dynamic.dotted.default.yml new file mode 100644 index 0000000..6e2af21 --- /dev/null +++ b/core/modules/config/tests/config_install_fail/config/config_test.dynamic.dotted.default.yml @@ -0,0 +1,6 @@ +id: dotted.default +label: 'Config install fail' +weight: 0 +protected_property: Default +# Intentionally commented out to verify default status behavior. +# status: 1 diff --git a/core/modules/config/tests/config_install_fail/config_install_fail.info.yml b/core/modules/config/tests/config_install_fail/config_install_fail.info.yml new file mode 100644 index 0000000..ebe72ad --- /dev/null +++ b/core/modules/config/tests/config_install_fail/config_install_fail.info.yml @@ -0,0 +1,8 @@ +name: 'Configuration test install fial' +type: module +package: Testing +version: VERSION +core: 8.x +hidden: true +dependencies: + - config_test diff --git a/core/modules/config/tests/config_install_fail/config_install_fail.module b/core/modules/config/tests/config_install_fail/config_install_fail.module new file mode 100644 index 0000000..e77c7ce --- /dev/null +++ b/core/modules/config/tests/config_install_fail/config_install_fail.module @@ -0,0 +1,6 @@ +