function ConfigConfigurator::getConfigStorage
Same name in other branches
- 10 core/lib/Drupal/Core/Recipe/ConfigConfigurator.php \Drupal\Core\Recipe\ConfigConfigurator::getConfigStorage()
Gets a config storage object for reading config from the recipe.
Return value
\Drupal\Core\Config\StorageInterface The config storage object for reading config from the recipe.
1 call to ConfigConfigurator::getConfigStorage()
- ConfigConfigurator::__construct in core/
lib/ Drupal/ Core/ Recipe/ ConfigConfigurator.php
File
-
core/
lib/ Drupal/ Core/ Recipe/ ConfigConfigurator.php, line 101
Class
- ConfigConfigurator
- @internal This API is experimental.
Namespace
Drupal\Core\RecipeCode
public function getConfigStorage() : StorageInterface {
$storages = [];
if ($this->recipeConfigDirectory) {
// Config provided by the recipe should take priority over config from
// extensions.
$storages[] = new FileStorage($this->recipeConfigDirectory);
}
if (!empty($this->config['import'])) {
/** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */
$module_list = \Drupal::service('extension.list.module');
/** @var \Drupal\Core\Extension\ThemeExtensionList $theme_list */
$theme_list = \Drupal::service('extension.list.theme');
foreach ($this->config['import'] as $extension => $names) {
// If the recipe explicitly does not want to import any config from this
// extension, skip it.
if ($names === NULL) {
continue;
}
$path = match (TRUE) { $module_list->exists($extension) => $module_list->getPath($extension),
$theme_list->exists($extension) => $theme_list->getPath($extension),
default => throw new \RuntimeException("{$extension} is not a theme or module"),
};
$storage = new RecipeConfigStorageWrapper(new FileStorage($path . '/config/install'), new FileStorage($path . '/config/optional'));
// If we get here, $names is either '*', or a list of config names
// provided by the current extension. In the latter case, we only want
// to import the config that is in the list, so use an
// AllowListConfigStorage to filter out the extension's other config.
if ($names && is_array($names)) {
$storage = new AllowListConfigStorage($storage, $names);
}
$storages[] = $storage;
}
}
$storage = RecipeConfigStorageWrapper::createStorageFromArray($storages);
if ($this->strict) {
return $storage;
}
// If we're not in strict mode, we only want to import config that doesn't
// exist yet in active storage.
$names = array_diff($storage->listAll(), \Drupal::service('config.storage')->listAll());
return $names ? new AllowListConfigStorage($storage, $names) : new NullStorage();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.