You are here

public function KeyConfigOverrides::loadOverrides in Key 8

Returns config overrides.

Parameters

array $names: A list of configuration names that are being loaded.

Return value

array An array keyed by configuration name of override data. Override data contains a nested array structure of overrides.

Overrides ConfigFactoryOverrideInterface::loadOverrides

File

src/KeyConfigOverrides.php, line 61

Class

KeyConfigOverrides
Provides key overrides for configuration.

Namespace

Drupal\key

Code

public function loadOverrides($names) {
  if ($this->inOverride) {
    return [];
  }
  $this->inOverride = TRUE;
  $mapping = $this
    ->getMapping();
  if (!$mapping) {
    return [];
  }
  try {
    $storage = \Drupal::entityTypeManager()
      ->getStorage('key');
  } catch (\Exception $e) {
    return [];
  }
  $overrides = [];
  foreach ($names as $name) {
    if (!array_key_exists($name, $mapping)) {
      continue;
    }
    $override = [];
    foreach ($mapping[$name] as $config_item => $key_id) {
      $key_value = $storage
        ->load($key_id)
        ->getKeyValue();
      if (!isset($key_value)) {
        continue;
      }

      // Turn the dot-separated configuration item name into a nested
      // array and set the value.
      $config_item_parents = explode('.', $config_item);
      NestedArray::setValue($override, $config_item_parents, $key_value);
    }
    if ($override) {
      $overrides[$name] = $override;
    }
  }
  $this->inOverride = FALSE;
  return $overrides;
}