Manages config type plugins.
Expanded class hierarchy of TypedConfigManager
class TypedConfigManager extends TypedDataManager {
/**
* A storage controller instance for reading configuration data.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $configStorage;
/**
* Creates a new typed configuration manager.
*
* @param \Drupal\Core\Config\StorageInterface $configStorage
* The storage controller object to use for reading schema data
* @param \Drupal\Core\Config\StorageInterface $schemaStorage
* The storage controller object to use for reading schema data
*/
public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage) {
$this->configStorage = $configStorage;
$this->discovery = new SchemaDiscovery($schemaStorage);
$this->factory = new TypedConfigElementFactory($this->discovery);
}
/**
* Gets typed configuration data.
*
* @param string $name
* Configuration object name.
*
* @return \Drupal\Core\Config\Schema\Element
* Typed configuration element.
*/
public function get($name) {
$data = $this->configStorage
->read($name);
$definition = $this
->getDefinition($name);
return $this
->create($definition, $data);
}
/**
* Overrides \Drupal\Core\TypedData\TypedDataManager::create()
*
* Fills in default type and does variable replacement.
*/
public function create(array $definition, $value = NULL, $name = NULL, $parent = NULL) {
if (!isset($definition['type'])) {
// Set default type 'string' if possible. If not it will be 'undefined'.
if (is_string($value)) {
$definition['type'] = 'string';
}
else {
$definition['type'] = 'undefined';
}
}
elseif (strpos($definition['type'], ']')) {
// Replace variable names in definition.
$replace = is_array($value) ? $value : array();
if (isset($parent)) {
$replace['%parent'] = $parent
->getValue();
}
if (isset($name)) {
$replace['%key'] = $name;
}
$definition['type'] = $this
->replaceName($definition['type'], $replace);
}
// Create typed config object.
return parent::create($definition, $value, $name, $parent);
}
/**
* Replaces variables in configuration name.
*
* The configuration name may contain one or more variables to be replaced,
* enclosed in square brackets like '[name]' and will follow the replacement
* rules defined by the replaceVariable() method.
*
* @param string $name
* Configuration name with variables in square brackets.
* @param mixed $data
* Configuration data for the element.
* @return string
* Configuration name with variables replaced.
*/
protected static function replaceName($name, $data) {
if (preg_match_all("/\\[(.*)\\]/U", $name, $matches)) {
// Build our list of '[value]' => replacement.
foreach (array_combine($matches[0], $matches[1]) as $key => $value) {
$replace[$key] = self::replaceVariable($value, $data);
}
return strtr($name, $replace);
}
else {
return $name;
}
}
/**
* Replaces variable values in included names with configuration data.
*
* Variable values are nested configuration keys that will be replaced by
* their value or some of these special strings:
* - '%key', will be replaced by the element's key.
* - '%parent', to reference the parent element.
*
* There may be nested configuration keys separated by dots or more complex
* patterns like '%parent.name' which references the 'name' value of the
* parent element.
*
* Example patterns:
* - 'name.subkey', indicates a nested value of the current element.
* - '%parent.name', will be replaced by the 'name' value of the parent.
* - '%parent.%key', will be replaced by the parent element's key.
*
* @param string $value
* Variable value to be replaced.
*
* @return string
* The replaced value if a replacement found or the original value if not.
*/
protected static function replaceVariable($value, $data) {
$parts = explode('.', $value);
// Process each value part, one at a time.
while ($name = array_shift($parts)) {
if (!is_array($data) || !isset($data[$name])) {
// Key not found, return original value
return $value;
}
elseif (!$parts) {
// If no more parts left, this is the final property.
return (string) $data[$name];
}
else {
// Get nested value and continue processing.
$data = $data[$name];
}
}
}
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginManagerBase:: |
protected | property | The object that discovers plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that instantiates plugins managed by this manager. | |
PluginManagerBase:: |
protected | property | The object that returns the preconfigured plugin instance appropriate for a particular runtime condition. | |
PluginManagerBase:: |
public | function |
Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface:: |
|
PluginManagerBase:: |
public | function |
Gets a specific plugin definition. Overrides DiscoveryInterface:: |
|
PluginManagerBase:: |
public | function |
Gets the definition of all plugins for this type. Overrides DiscoveryInterface:: |
|
PluginManagerBase:: |
public | function | Performs extra processing on plugin definitions. | 2 |
TypedConfigManager:: |
protected | property | A storage controller instance for reading configuration data. | |
TypedConfigManager:: |
public | function |
Overrides \Drupal\Core\TypedData\TypedDataManager::create() Overrides TypedDataManager:: |
|
TypedConfigManager:: |
public | function | Gets typed configuration data. | 1 |
TypedConfigManager:: |
protected static | function | Replaces variables in configuration name. | |
TypedConfigManager:: |
protected static | function | Replaces variable values in included names with configuration data. | |
TypedConfigManager:: |
public | function |
Creates a new typed configuration manager. Overrides TypedDataManager:: |
1 |
TypedDataManager:: |
protected | property | The validation constraint manager to use for instantiating constraints. | |
TypedDataManager:: |
protected | property |
Type definition defaults which are merged in by the ProcessDecorator. Overrides PluginManagerBase:: |
|
TypedDataManager:: |
protected | property | An array of typed data property prototypes. | |
TypedDataManager:: |
protected | property | The validator used for validating typed data. | |
TypedDataManager:: |
public | function |
Implements \Drupal\Component\Plugin\PluginManagerInterface::createInstance(). Overrides PluginManagerBase:: |
|
TypedDataManager:: |
public | function | Gets configured constraints from a data definition. | |
TypedDataManager:: |
public | function |
Implements \Drupal\Component\Plugin\PluginManagerInterface::getInstance(). Overrides PluginManagerBase:: |
|
TypedDataManager:: |
public | function | Get a typed data instance for a property of a given typed data object. | |
TypedDataManager:: |
public | function | Gets the validation constraint manager. | |
TypedDataManager:: |
public | function | Gets the validator for validating typed data. | |
TypedDataManager:: |
public | function | Sets the validation constraint manager. | |
TypedDataManager:: |
public | function | Sets the validator for validating typed data. |