Commit 808263b1 authored by catch's avatar catch

Issue #3002655 by alexpott, johnpicozzi, nathandentzau, larowlan: Optional...

Issue #3002655 by alexpott, johnpicozzi, nathandentzau, larowlan: Optional profile configuration can be unexpectedly recreated after being deleted
parent dc19a1b0
......@@ -160,7 +160,10 @@ public function installDefaultConfig($type, $name) {
*/
public function installOptionalConfig(StorageInterface $storage = NULL, $dependency = []) {
$profile = $this->drupalGetProfile();
$optional_profile_config = [];
$enabled_extensions = $this->getEnabledExtensions();
$existing_config = $this->getActiveStorages()->listAll();
// Create the storages to read configuration from.
if (!$storage) {
// Search the install profile's optional configuration too.
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE, $this->installProfile);
......@@ -171,7 +174,6 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende
// Creates a profile storage to search for overrides.
$profile_install_path = $this->drupalGetPath('module', $profile) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
$profile_storage = new FileStorage($profile_install_path, StorageInterface::DEFAULT_COLLECTION);
$optional_profile_config = $profile_storage->listAll();
}
else {
// Profile has not been set yet. For example during the first steps of the
......@@ -179,10 +181,17 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende
$profile_storage = NULL;
}
$enabled_extensions = $this->getEnabledExtensions();
$existing_config = $this->getActiveStorages()->listAll();
// Build the list of possible configuration to create.
$list = $storage->listAll();
if ($profile_storage && !empty($dependency)) {
// Only add the optional profile configuration into the list if we are
// have a dependency to check. This ensures that optional profile
// configuration is not unexpectedly re-created after being deleted.
$list = array_unique(array_merge($list, $profile_storage->listAll()));
}
$list = array_unique(array_merge($storage->listAll(), $optional_profile_config));
// Filter the list of configuration to only include configuration that
// should be created.
$list = array_filter($list, function ($config_name) use ($existing_config) {
// Only list configuration that:
// - does not already exist
......@@ -226,6 +235,8 @@ public function installOptionalConfig(StorageInterface $storage = NULL, $depende
unset($all_config[$config_name]);
}
}
// Create the optional configuration if there is any left after filtering.
if (!empty($config_to_create)) {
$this->createConfiguration(StorageInterface::DEFAULT_COLLECTION, $config_to_create, TRUE);
}
......
......@@ -43,7 +43,8 @@ public function installDefaultConfig($type, $name);
* @param \Drupal\Core\Config\StorageInterface $storage
* (optional) The configuration storage to search for optional
* configuration. If not provided, all enabled extension's optional
* configuration directories will be searched.
* configuration directories including the install profile's will be
* searched.
* @param array $dependency
* (optional) If set, ensures that the configuration being installed has
* this dependency. The format is dependency type as the key ('module',
......
......@@ -107,7 +107,16 @@ public function testInstallProfileConfigOverwrite() {
$this->container->get('module_installer')->install(['dblog']);
$this->rebuildContainer();
$this->assertEqual($config_test_storage->load('override_unmet')->label(), 'Override', 'The optional config_test entity is overridden by the profile optional configuration and is installed when its dependencies are met.');
$this->assertEqual($config_test_storage->load('completely_new')->label(), 'Completely new optional configuration', 'The optional config_test entity is provided by the profile optional configuration and is installed when its dependencies are met.');
$config_test_new = $config_test_storage->load('completely_new');
$this->assertEqual($config_test_new->label(), 'Completely new optional configuration', 'The optional config_test entity is provided by the profile optional configuration and is installed when its dependencies are met.');
$config_test_new->delete();
// Install another module that provides optional configuration and ensure
// that deleted profile configuration is not re-created.
$this->container->get('module_installer')->install(['config_other_module_config_test']);
$this->rebuildContainer();
$config_test_storage = \Drupal::entityManager()->getStorage('config_test');
$this->assertNull($config_test_storage->load('completely_new'));
}
}
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