function TypedConfigManager::replaceName

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Config/TypedConfigManager.php \Drupal\Core\Config\TypedConfigManager::replaceName()
  2. 10 core/lib/Drupal/Core/Config/TypedConfigManager.php \Drupal\Core\Config\TypedConfigManager::replaceName()

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.

Parameters

string $name: Configuration name with variables in square brackets.

mixed $data: Configuration data for the element.

Return value

string Configuration name with variables replaced.

2 calls to TypedConfigManager::replaceName()
TypedConfigManager::buildDataDefinition in core/lib/Drupal/Core/Config/TypedConfigManager.php
Creates a new data definition object from a type definition array and actual configuration data. Since type definitions may contain variables to be replaced, we need the configuration value to create it.
TypedConfigManager::getDefinitionWithReplacements in core/lib/Drupal/Core/Config/TypedConfigManager.php
Gets a schema definition with replacements for dynamic names.

File

core/lib/Drupal/Core/Config/TypedConfigManager.php, line 276

Class

TypedConfigManager
Manages config schema type plugins.

Namespace

Drupal\Core\Config

Code

protected function replaceName($name, $data) {
    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] = $this->replaceVariable($value, $data);
        }
        return strtr($name, $replace);
    }
    else {
        return $name;
    }
}

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