function TypeResolver::resolveDynamicTypeName

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Config/Schema/TypeResolver.php \Drupal\Core\Config\Schema\TypeResolver::resolveDynamicTypeName()

Replaces dynamic type expressions in configuration type.

The configuration type name may contain one or more expressions to be replaced, enclosed in square brackets like '[name]' or '[%parent.id]' and will follow the replacement rules defined by the resolveExpression() method.

Parameters

string $name: Configuration type, potentially with expressions in square brackets.

array $data: Configuration data for the element.

Return value

string Configuration type name with all expressions resolved.

6 calls to TypeResolver::resolveDynamicTypeName()
EntityBundleExistsConstraintValidator::validate in core/lib/Drupal/Core/Validation/Plugin/Validation/Constraint/EntityBundleExistsConstraintValidator.php
TypedConfigManager::buildDataDefinition in core/lib/Drupal/Core/Config/TypedConfigManager.php
TypedConfigManager::getDefinitionWithReplacements in core/lib/Drupal/Core/Config/TypedConfigManager.php
Gets a schema definition with replacements for dynamic type names.
TypedConfigManager::replaceName in core/lib/Drupal/Core/Config/TypedConfigManager.php
Replaces dynamic type expressions in configuration type.
TypedConfigManager::resolveDynamicTypeName in core/lib/Drupal/Core/Config/TypedConfigManager.php
Resolves a dynamic type name.

... See full list

File

core/lib/Drupal/Core/Config/Schema/TypeResolver.php, line 34

Class

TypeResolver
Provides helper methods for resolving config schema types.

Namespace

Drupal\Core\Config\Schema

Code

public static function resolveDynamicTypeName(string $name, mixed $data) : string {
    if (preg_match_all("/\\[(.*)\\]/U", $name, $matches)) {
        // Build our list of '[value]' => replacement.
        $replace = [];
        foreach (array_combine($matches[0], $matches[1]) as $key => $value) {
            $replace[$key] = self::resolveExpression($value, $data);
        }
        return strtr($name, $replace);
    }
    return $name;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.