You are here

protected function ConfigSplitIgnoreFilter::activeRead in Configuration Split Ignore 8

Read from the active configuration.

This method will read the configuration from the active config store. But rather than just straight up returning the value it will check if a nested config key is set to be ignored and set only that value on the data to be filtered.

Parameters

string $name: The name of the configuration to read.

mixed $data: The data to be filtered.

Return value

mixed The data filtered or read from the active storage.

Overrides IgnoreFilter::activeRead

File

src/Plugin/ConfigFilter/ConfigSplitIgnoreFilter.php, line 112

Class

ConfigSplitIgnoreFilter
Provides a ignore filter that allows to delete the configuration entities.

Namespace

Drupal\config_split_ignore\Plugin\ConfigFilter

Code

protected function activeRead($name, $data) {
  $keys = [];
  foreach ($this->configuration['ignored'] as $ignored) {
    if (strpos($ignored, static::DELETION_PREFIX) === 0) {
      continue;
    }

    // Split the ignore settings so that we can ignore individual keys.
    $ignored = explode(':', $ignored, 2);
    if ($this
      ->stringMatch($ignored[0], $name)) {
      if (count($ignored) == 1) {

        // If one of the definitions does not have keys ignore the
        // whole config. If the active configuration doesn't exist,
        // allow to create it.
        $active = $this->active
          ->read($name);
        return $active ? $active : $data;
      }
      else {

        // Add the sub parts to ignore to the keys.
        $keys[] = $ignored[1];
      }
    }
  }
  $active = $this->active
    ->read($name);
  if (!$active) {
    return $data;
  }
  foreach ($keys as $key) {
    $parts = explode('.', $key);
    if (count($parts) == 1) {
      if (isset($active[$key])) {
        $data[$key] = $active[$key];
      }
    }
    else {
      $key_exists = FALSE;
      $value = NestedArray::getValue($active, $parts, $key_exists);
      if ($key_exists) {

        // Enforce the value if it existed in the active config.
        NestedArray::setValue($data, $parts, $value, TRUE);
      }
    }
  }
  return $data;
}