diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php index 5bedbbe..60f4188 100644 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -63,6 +63,15 @@ protected function getAllFolders() { if (isset($themes['enabled'])) { $this->folders += $this->getComponentNames('theme', array_keys($themes['enabled'])); } + + // The install profile can override module default configuration. We do + // this by replacing the config file path from the module/theme with the + // install profile version if there are any duplicates. + $profile_folders = $this->getComponentNames('profile', array(drupal_get_profile())); + $folders_to_replace = array_intersect_key($profile_folders, $this->folders); + if (!empty($folders_to_replace)) { + $this->folders = array_merge($this->folders, $folders_to_replace); + } } return $this->folders; } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php index 0fd3f5e..df3d103 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php @@ -8,6 +8,7 @@ namespace Drupal\config\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\Core\Config\FileStorage; /** * Tests installation of configuration objects in installation functionality. @@ -96,4 +97,62 @@ function testIntegrationModuleReinstallation() { $this->assertIdentical($config_entity->get('label'), 'Customized integration config label'); } + /** + * Tests install profile config changes. + */ + function testInstallProfileConfigOverwrite() { + $config_name = 'system.cron'; + // The expected configuration from the system module. + $expected_original_data = array( + 'threshold' => array( + 'autorun' => 0, + 'requirements_warning' => 172800, + 'requirements_error' => 1209600, + ), + ); + // The expected active configuration altered by the install profile. + $expected_overriden_data = array( + 'threshold' => array( + 'autorun' => 0, + 'requirements_warning' => 259200, + 'requirements_error' => 1209600, + ), + ); + + // Enter an override-free context to ensure the original data remains. + $old_state = \Drupal::configFactory()->getOverrideState(); + \Drupal::configFactory()->setOverrideState(FALSE); + + // Verify that the original data matches. We have to read the module config + // file directly, otherwise install profile overrides will apply. + $config_dir = drupal_get_path('module', 'system') . '/config'; + $this->assertTrue(is_dir($config_dir)); + $source_storage = new FileStorage($config_dir); + $data = $source_storage->read($config_name); + $this->assertIdentical($data, $expected_original_data); + + // Verify that active configuration matches the expected data, which has + // been overriden by the testing install profile. + $config = \Drupal::config($config_name); + $this->assertIdentical($config->get(), $expected_overriden_data); + + // Turn on the test module, which will also attempt to override the + // configuration data, but should be prevented. + \Drupal::moduleHandler()->install(array('config_override_test')); + + // Verify that the test module has not been able to change the data. + $config = \Drupal::config($config_name); + $this->assertIdentical($config->get(), $expected_overriden_data); + + // Disable and uninstall the test module. + \Drupal::moduleHandler()->uninstall(array('config_override_test')); + + // Verify that the data hasn't been altered by removing the test module. + $config = \Drupal::config($config_name); + $this->assertIdentical($config->get(), $expected_overriden_data); + + // Re-enable configuration overrides. + \Drupal::configFactory()->setOverrideState($old_state); + } + } diff --git a/core/modules/config/tests/config_override_test/config/system.cron.yml b/core/modules/config/tests/config_override_test/config/system.cron.yml new file mode 100644 index 0000000..79f797f --- /dev/null +++ b/core/modules/config/tests/config_override_test/config/system.cron.yml @@ -0,0 +1,5 @@ +threshold: + autorun: 0 + requirements_warning: 172800 + requirements_error: 1209600 + diff --git a/core/modules/config/tests/config_override_test/config_override_test.module b/core/modules/config/tests/config_override_test/config_override_test.module new file mode 100644 index 0000000..f364ffb --- /dev/null +++ b/core/modules/config/tests/config_override_test/config_override_test.module @@ -0,0 +1,6 @@ +