/** * {@inheritdoc} */ public function installOptionalConfig(StorageInterface $storage = NULL, $dependency = []) { 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); // The extension install storage ensures that overrides are used. $profile_storage = NULL; } else { // Creates a profile storage to search for overrides. $profile_install_path = $this->drupalGetPath('module', $this->drupalGetProfile()) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY; $profile_storage = new FileStorage($profile_install_path, StorageInterface::DEFAULT_COLLECTION); } $collection_info = $this->configManager->getConfigCollectionInfo(); $enabled_extensions = $this->getEnabledExtensions(); foreach ($collection_info->getCollectionNames() as $collection) { if (!$this->configManager->supportsConfigurationEntities($collection)) { continue; } $existing_config = $this->getActiveStorages($collection)->listAll(); $list = array_filter($storage->listAll(), function ($config_name) use($existing_config) { // Only list configuration that: // - does not already exist // - is a configuration entity (this also excludes config that has an // implicit dependency on modules that are not yet installed) return !in_array($config_name, $existing_config) && $this->configManager->getEntityTypeIdByName($config_name); }); $all_config = array_merge($existing_config, $list); $config_to_create = $storage->readMultiple($list); // Check to see if the corresponding override storage has any overrides. if ($profile_storage) { if ($profile_storage->getCollectionName() != $collection) { $profile_storage = $profile_storage->createCollection($collection); } $config_to_create = $profile_storage->readMultiple($list) + $config_to_create; } foreach ($config_to_create as $config_name => $data) { // Exclude configuration where its dependencies cannot be met. if (!$this->validateDependencies($config_name, $data, $enabled_extensions, $all_config)) { unset($config_to_create[$config_name]); } elseif (!empty($dependency)) { // Create a light weight dependency object to check dependencies. $config_entity = new ConfigEntityDependency($config_name, $data); if (!$config_entity->hasDependency(key($dependency), reset($dependency))) { unset($config_to_create[$config_name]); } } } if (!empty($config_to_create)) { $this->createConfiguration($collection, $config_to_create, TRUE); } } }