trait ConfigReadonlyWhitelistTrait in Configuration Read-only mode 8
Trait ConfigReadonlyWhitelistTrait.
@package Drupal\config_readonly
Hierarchy
- trait \Drupal\config_readonly\ConfigReadonlyWhitelistTrait
2 files declare their use of ConfigReadonlyWhitelistTrait
- ConfigReadonlyStorage.php in src/
Config/ ConfigReadonlyStorage.php - ReadOnlyFormSubscriber.php in src/
EventSubscriber/ ReadOnlyFormSubscriber.php
File
- src/
ConfigReadonlyWhitelistTrait.php, line 12
Namespace
Drupal\config_readonlyView source
trait ConfigReadonlyWhitelistTrait {
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* An array to store the whitelist ignore patterns.
*
* @var string[]
*/
protected $patterns = [];
/**
* Set the module handler.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler to invoke hooks.
*/
protected function setModuleHandler(ModuleHandlerInterface $module_handler) {
$this->moduleHandler = $module_handler;
}
/**
* Get whitelist patterns.
*
* @return string[]
* The whitelist patterns.
*/
protected function getWhitelistPatterns() {
if (!$this->patterns) {
$this->patterns = $this->moduleHandler
->invokeAll('config_readonly_whitelist_patterns');
}
return $this->patterns;
}
/**
* Check if the given name matches any whitelist pattern.
*
* @param string $name
* The config name.
*
* @return bool
* Whether or not there is a match.
*/
protected function matchesWhitelistPattern($name) {
// Check for matches.
$patterns = $this
->getWhitelistPatterns();
if ($patterns) {
foreach ($patterns as $pattern) {
$escaped = str_replace('\\*', '.*', preg_quote($pattern, '/'));
if (preg_match('/^' . $escaped . '$/', $name)) {
return TRUE;
}
}
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigReadonlyWhitelistTrait:: |
protected | property | The module handler. | |
ConfigReadonlyWhitelistTrait:: |
protected | property | An array to store the whitelist ignore patterns. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Get whitelist patterns. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Check if the given name matches any whitelist pattern. | |
ConfigReadonlyWhitelistTrait:: |
protected | function | Set the module handler. |