function TypeResolver::resolveDynamicTypeName

Same name in other branches
  1. 10 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.

4 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
Creates a new data definition object.
TypedConfigManager::getDefinitionWithReplacements in core/lib/Drupal/Core/Config/TypedConfigManager.php
Gets a schema definition with replacements for dynamic type names.
TypeResolverTest::testInvalidType in core/tests/Drupal/Tests/Core/Config/TypeResolverTest.php
@testWith ["[foo.%bar.qux]", "`foo.%bar.qux` is not a valid dynamic type expression. Dynamic type expressions must contain at least `%parent`, `%key`, or `%type`.`", {"foo":…

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.