class StatusOverride in Configuration Split 2.0.x
A config override for config split based on the drupal state.
Hierarchy
- class \Drupal\config_split\Config\StatusOverride implements ConfigFactoryOverrideInterface
Expanded class hierarchy of StatusOverride
6 files declare their use of StatusOverride
- ConfigSplitActivateForm.php in src/
Form/ ConfigSplitActivateForm.php - ConfigSplitCliService.php in src/
ConfigSplitCliService.php - ConfigSplitDeactivateForm.php in src/
Form/ ConfigSplitDeactivateForm.php - ConfigSplitEntityForm.php in src/
Form/ ConfigSplitEntityForm.php - ConfigSplitEntityListBuilder.php in src/
ConfigSplitEntityListBuilder.php
1 string reference to 'StatusOverride'
1 service uses StatusOverride
File
- src/
Config/ StatusOverride.php, line 15
Namespace
Drupal\config_split\ConfigView source
class StatusOverride implements ConfigFactoryOverrideInterface {
/**
* The drupal state.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The cache invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
*/
protected $cacheInvalidator;
/**
* The service constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The drupal state.
* @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cacheInvalidator
* The cache invalidator.
*/
public function __construct(StateInterface $state, CacheTagsInvalidatorInterface $cacheInvalidator) {
$this->state = $state;
$this->cacheInvalidator = $cacheInvalidator;
}
/**
* Set a config split state locally.
*
* @param string $name
* The name of the config split.
* @param bool|null $active
* The state, null to reset.
*/
public function setSplitOverride(string $name, bool $active = NULL) {
$name = self::fixName($name);
$overrides = $this->state
->get('config_split_override_state', []);
if ($active === NULL) {
unset($overrides[$name]);
}
else {
$overrides[$name] = $active;
}
$this->state
->set('config_split_override_state', $overrides);
$this->cacheInvalidator
->invalidateTags($this
->getCacheableMetadata('config_split.config_split.' . $name)
->getCacheTags());
}
/**
* Get the split override setting.
*
* @param string $name
* The name of the split.
*
* @return bool|null
* The state, null if not managed.
*/
public function getSplitOverride(string $name) {
$name = self::fixName($name);
$overrides = $this->state
->get('config_split_override_state', []);
if (isset($overrides[$name])) {
return (bool) $overrides[$name];
}
return NULL;
}
/**
* Check settings.php for overrides.
*
* @param string $name
* The name of the split.
*
* @return bool|null
* The overridden status from settings.php
*/
public function getSettingsOverride(string $name) {
$name = 'config_split.config_split.' . self::fixName($name);
// This assumes that the config is overwritten as recommended.
if (isset($GLOBALS['config'][$name], $GLOBALS['config'][$name]['status'])) {
return (bool) $GLOBALS['config'][$name]['status'];
}
return NULL;
}
/**
* {@inheritdoc}
*/
public function loadOverrides($names) {
$overrides = [];
foreach ($this->state
->get('config_split_override_state', []) as $name => $status) {
$name = 'config_split.config_split.' . $name;
if (in_array($name, $names)) {
$overrides = $overrides + [
$name => [
'status' => (bool) $status,
],
];
}
}
return $overrides;
}
/**
* {@inheritdoc}
*/
public function getCacheSuffix() {
return 'config_split_state';
}
/**
* {@inheritdoc}
*/
public function createConfigObject($name, $collection = StorageInterface::DEFAULT_COLLECTION) {
return NULL;
}
/**
* {@inheritdoc}
*/
public function getCacheableMetadata($name) {
$metadata = new CacheableMetadata();
$metadata
->setCacheTags([
$this
->getCacheSuffix() . ':' . $name,
'config:' . $name,
])
->setCacheMaxAge(Cache::PERMANENT);
return $metadata;
}
/**
* Make sure the split name is just the machine name.
*
* @param string $name
* The split name.
*
* @return string
* The split name.
*/
private static function fixName(string $name) : string {
if (strpos($name, 'config_split.config_split.') === 0) {
return substr($name, strlen('config_split.config_split.'));
}
return $name;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
StatusOverride:: |
protected | property | The cache invalidator. | |
StatusOverride:: |
protected | property | The drupal state. | |
StatusOverride:: |
public | function |
Creates a configuration object for use during install and synchronization. Overrides ConfigFactoryOverrideInterface:: |
|
StatusOverride:: |
private static | function | Make sure the split name is just the machine name. | |
StatusOverride:: |
public | function |
Gets the cacheability metadata associated with the config factory override. Overrides ConfigFactoryOverrideInterface:: |
|
StatusOverride:: |
public | function |
The string to append to the configuration static cache name. Overrides ConfigFactoryOverrideInterface:: |
|
StatusOverride:: |
public | function | Check settings.php for overrides. | |
StatusOverride:: |
public | function | Get the split override setting. | |
StatusOverride:: |
public | function |
Returns config overrides. Overrides ConfigFactoryOverrideInterface:: |
|
StatusOverride:: |
public | function | Set a config split state locally. | |
StatusOverride:: |
public | function | The service constructor. |