function TypedConfigManager::getDefinitionWithReplacements

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

Gets a schema definition with replacements for dynamic type names.

Parameters

string $base_plugin_id: A plugin ID.

array $replacements: An array of replacements for dynamic type names.

bool $exception_on_invalid: (optional) This parameter is passed along to self::getDefinition(). However, self::getDefinition() does not respect this parameter, so it is effectively useless in this context.

Return value

array A schema definition array.

2 calls to TypedConfigManager::getDefinitionWithReplacements()
TypedConfigManager::buildDataDefinition in core/lib/Drupal/Core/Config/TypedConfigManager.php
Creates a new data definition object.
TypedConfigManager::getDefinition in core/lib/Drupal/Core/Config/TypedConfigManager.php
Gets a specific plugin definition.

File

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

Class

TypedConfigManager
Manages config schema type plugins.

Namespace

Drupal\Core\Config

Code

protected function getDefinitionWithReplacements($base_plugin_id, array $replacements, $exception_on_invalid = TRUE) {
  $definitions = $this->getDefinitions();
  $type = $this->determineType($base_plugin_id, $definitions);
  $definition = $definitions[$type];
  // Check whether this type is an extension of another one and compile it.
  if (isset($definition['type'])) {
    $merge = $this->getDefinition($definition['type'], $exception_on_invalid);
    // Preserve integer keys on merge, so sequence item types can override
    // parent settings as opposed to adding unused second, third, etc. items.
    $definition = NestedArray::mergeDeepArray([
      $merge,
      $definition,
    ], TRUE);
    // Replace dynamic portions of the definition type.
    if (!empty($replacements) && strpos($definition['type'], ']')) {
      $sub_type = $this->determineType(TypeResolver::resolveDynamicTypeName($definition['type'], $replacements), $definitions);
      $sub_definition = $definitions[$sub_type];
      if (isset($definitions[$sub_type]['type'])) {
        $sub_merge = $this->getDefinition($definitions[$sub_type]['type'], $exception_on_invalid);
        $sub_definition = NestedArray::mergeDeepArray([
          $sub_merge,
          $definitions[$sub_type],
        ], TRUE);
      }
      // Merge the newly determined subtype definition with the original
      // definition.
      $definition = NestedArray::mergeDeepArray([
        $sub_definition,
        $definition,
      ], TRUE);
      $type = "{$type}||{$sub_type}";
    }
    // Unset type so we try the merge only once per type.
    unset($definition['type']);
    $this->definitions[$type] = $definition;
  }
  // Add type and default definition class.
  $definition += [
    'definition_class' => '\\Drupal\\Core\\TypedData\\DataDefinition',
    'type' => $type,
    'unwrap_for_canonical_representation' => TRUE,
  ];
  return $definition;
}

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