You are here

protected function IgnoreFilter::activeRead in Config Ignore 8.2

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.

2 calls to IgnoreFilter::activeRead()
IgnoreFilter::activeReadMultiple in src/Plugin/ConfigFilter/IgnoreFilter.php
Read multiple from the active storage.
IgnoreFilter::filterRead in src/Plugin/ConfigFilter/IgnoreFilter.php

File

src/Plugin/ConfigFilter/IgnoreFilter.php, line 117

Class

IgnoreFilter
Provides a ignore filter that reads partly from the active storage.

Namespace

Drupal\config_ignore\Plugin\ConfigFilter

Code

protected function activeRead($name, $data) {
  $keys = [];
  foreach ($this->configuration['ignored'] as $ignored) {

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

        // If one of the definitions does not have keys ignore the
        // whole config.
        return $this->active
          ->read($name);
      }
      else {

        // Add the sub parts to ignore to the keys.
        $keys[] = $ignored[1];
      }
    }
  }
  $active = $this->active
    ->read($name);
  if (!$active || !$data) {
    return $data;
  }
  foreach ($keys as $key) {
    $parts = explode('.', $key);
    if (count($parts) == 1) {
      if (isset($active[$key])) {
        $data[$key] = $active[$key];
      }
    }
    else {
      $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;
}