class SiteConfigOverrides in Config override 8
Hierarchy
- class \Drupal\config_override\SiteConfigOverrides implements ConfigFactoryOverrideInterface
Expanded class hierarchy of SiteConfigOverrides
1 file declares its use of SiteConfigOverrides
- SiteConfigOverridesTest.php in tests/
Unit/ SiteConfigOverridesTest.php
1 string reference to 'SiteConfigOverrides'
1 service uses SiteConfigOverrides
File
- src/
SiteConfigOverrides.php, line 12
Namespace
Drupal\config_overrideView source
class SiteConfigOverrides implements ConfigFactoryOverrideInterface {
/**
* Constants for the override directory.
*/
const CONFIG_OVERRIDE_DIRECTORY = 'override';
/**
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
protected $cacheBackend;
/**
* The app root.
*
* @var string
*/
protected $root;
/**
* Creates a new SiteConfigOverrides instance.
*
* @param string $root
* The app root.
* @param \Drupal\Core\Cache\CacheBackendInterface $cacheBackend
* The cache backend.
*/
public function __construct($root, CacheBackendInterface $cacheBackend) {
$this->root = $root;
$this->cacheBackend = $cacheBackend;
}
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
if (!($directory = $this
->getSiteConfigOverrideFolder())) {
return $overrides;
}
if ($config = $this->cacheBackend
->get('config_overrides.site')) {
$overrides = $config->data;
}
else {
$storage = new FileStorage($this
->getSiteConfigOverrideFolder());
$overrides = $storage
->readMultiple($storage
->listAll());
$this->cacheBackend
->set('config_overrides.site', $overrides);
}
return array_intersect_key($overrides, array_flip($names));
}
/**
* Returns the site config overrides directory or NULL if it was not defined.
*
* @return string|null
* The site config overrides directory or NULL if it was not defined.
*/
protected function getSiteConfigOverrideFolder() {
try {
return $this->root . '/' . Settings::get('config_sync_directory');
} catch (\Exception $e) {
return NULL;
}
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'config_override.site';
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
return new CacheableMetadata();
}
/**
* {@inheritdoc}
*/
protected function configGetConfigDirectory($override) {
return 'sites/default/config/' . $override;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SiteConfigOverrides:: |
protected | property | ||
SiteConfigOverrides:: |
protected | property | The app root. | |
SiteConfigOverrides:: |
protected | function | ||
SiteConfigOverrides:: |
constant | Constants for the override directory. | ||
SiteConfigOverrides:: |
public | function |
Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface:: |
|
SiteConfigOverrides:: |
public | function |
Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface:: |
|
SiteConfigOverrides:: |
public | function |
The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface:: |
|
SiteConfigOverrides:: |
protected | function | Returns the site config overrides directory or NULL if it was not defined. | |
SiteConfigOverrides:: |
public | function |
Returns config overrides. Overrides ConfigFactoryOverrideInterface:: |
|
SiteConfigOverrides:: |
public | function | Creates a new SiteConfigOverrides instance. |