class KeyConfigOverrides in Key 8
Provides key overrides for configuration.
Hierarchy
- class \Drupal\key\KeyConfigOverrides implements ConfigFactoryOverrideInterface
Expanded class hierarchy of KeyConfigOverrides
1 string reference to 'KeyConfigOverrides'
1 service uses KeyConfigOverrides
File
- src/
KeyConfigOverrides.php, line 15
Namespace
Drupal\keyView source
class KeyConfigOverrides implements ConfigFactoryOverrideInterface {
/**
* Config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Cache backend.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheBackend;
/**
* Mapping.
*
* @var array
*/
protected $mapping;
/**
* In override.
*
* @var bool
*/
protected $inOverride = FALSE;
/**
* Creates a new ModuleConfigOverrides instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface|null $config_factory
* The config factory.
* @param \Drupal\Core\Cache\CacheBackendInterface|null $cache_backend
* The cache backend.
*/
public function __construct(ConfigFactoryInterface $config_factory = NULL, CacheBackendInterface $cache_backend = NULL) {
$this->configFactory = $config_factory ?: \Drupal::configFactory();
$this->cacheBackend = $cache_backend ?: \Drupal::cache('data');
}
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
if ($this->inOverride) {
return [];
}
$this->inOverride = TRUE;
$mapping = $this
->getMapping();
if (!$mapping) {
return [];
}
try {
$storage = \Drupal::entityTypeManager()
->getStorage('key');
} catch (\Exception $e) {
return [];
}
$overrides = [];
foreach ($names as $name) {
if (!array_key_exists($name, $mapping)) {
continue;
}
$override = [];
foreach ($mapping[$name] as $config_item => $key_id) {
$key_value = $storage
->load($key_id)
->getKeyValue();
if (!isset($key_value)) {
continue;
}
// Turn the dot-separated configuration item name into a nested
// array and set the value.
$config_item_parents = explode('.', $config_item);
NestedArray::setValue($override, $config_item_parents, $key_value);
}
if ($override) {
$overrides[$name] = $override;
}
}
$this->inOverride = FALSE;
return $overrides;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'key_config_override';
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* Get a mapping of key configuration overrides.
*
* @return array
* A mapping of key configuration overrides.
*/
protected function getMapping() {
if (!$this->mapping) {
$mapping = [];
$override_ids = $this->configFactory
->listAll('key.config_override.');
$overrides = $this->configFactory
->loadMultiple($override_ids);
foreach ($overrides as $id => $override) {
$override = $override
->get();
$config_id = '';
if (!empty($override['config_prefix'])) {
$config_id .= $override['config_prefix'] . '.';
}
if (isset($override['config_name'])) {
$config_id .= $override['config_name'];
}
$config_item = $override['config_item'];
$key_id = $override['key_id'];
$mapping[$config_id][$config_item] = $key_id;
}
$this->mapping = $mapping;
}
return $this->mapping;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyConfigOverrides:: |
protected | property | Cache backend. | |
KeyConfigOverrides:: |
protected | property | Config factory. | |
KeyConfigOverrides:: |
protected | property | In override. | |
KeyConfigOverrides:: |
protected | property | Mapping. | |
KeyConfigOverrides:: |
public | function |
Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface:: |
|
KeyConfigOverrides:: |
public | function |
Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface:: |
|
KeyConfigOverrides:: |
public | function |
The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface:: |
|
KeyConfigOverrides:: |
protected | function | Get a mapping of key configuration overrides. | |
KeyConfigOverrides:: |
public | function |
Returns config overrides. Overrides ConfigFactoryOverrideInterface:: |
|
KeyConfigOverrides:: |
public | function | Creates a new ModuleConfigOverrides instance. |