function TypedConfigManager::getStaticTypeRoot
Same name in other branches
- 10 core/lib/Drupal/Core/Config/TypedConfigManager.php \Drupal\Core\Config\TypedConfigManager::getStaticTypeRoot()
Gets the static type root for a config schema object.
Parameters
\Drupal\Core\TypedData\TraversableTypedDataInterface $object: A config schema object to get the static type root for.
Return value
\Drupal\Core\TypedData\TraversableTypedDataInterface The ancestral config schema object at which the static type root lies: either the first ancestor with a dynamic type (for example: `block.block.*:settings`, which has the `block.settings.[%parent.plugin]` type) or the (absolute) root of the config object (in this example: `block.block.*`).
2 calls to TypedConfigManager::getStaticTypeRoot()
- TypedConfigManager::buildDataDefinition in core/
lib/ Drupal/ Core/ Config/ TypedConfigManager.php - Creates a new data definition object.
- ValidKeysConstraintValidator::validate in core/
lib/ Drupal/ Core/ Validation/ Plugin/ Validation/ Constraint/ ValidKeysConstraintValidator.php
File
-
core/
lib/ Drupal/ Core/ Config/ TypedConfigManager.php, line 201
Class
- TypedConfigManager
- Manages config schema type plugins.
Namespace
Drupal\Core\ConfigCode
public static function getStaticTypeRoot(TraversableTypedDataInterface $object) : TraversableTypedDataInterface {
$root = $object->getRoot();
$static_type_root = NULL;
while ($static_type_root === NULL && $object !== $root) {
// Use the parent data definition to determine the type of this mapping
// (including the dynamic placeholders). For example:
// - `editor.settings.[%parent.editor]`
// - `editor.image_upload_settings.[status]`.
$parent_data_def = $object->getParent()
->getDataDefinition();
$original_mapping_type = match (TRUE) { $parent_data_def instanceof MapDataDefinition => $parent_data_def->toArray()['mapping'][$object->getName()]['type'],
$parent_data_def instanceof SequenceDataDefinition => $parent_data_def->toArray()['sequence']['type'],
default => throw new \LogicException('Invalid config schema detected.'),
};
// If this mapping's type was dynamically defined, then this is the static
// type root inside which all types are statically defined.
if (str_contains($original_mapping_type, ']')) {
$static_type_root = $object;
break;
}
$object = $object->getParent();
}
// Either the discovered static type root is not the actual root, or no
// static type root was found and it is the root config object.
assert($static_type_root !== NULL && $static_type_root !== $root || $static_type_root === NULL && $object->getParent() === NULL);
return $static_type_root ?? $root;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.