You are here

public function SplitFilter::filterWrite in Configuration Split 8

File

src/Plugin/ConfigFilter/SplitFilter.php, line 182

Class

SplitFilter
Provides a SplitFilter.

Namespace

Drupal\config_split\Plugin\ConfigFilter

Code

public function filterWrite($name, array $data) {
  if (!$this->secondaryStorage) {
    throw new \InvalidArgumentException('The split storage has to be set and exist for write operations.');
  }
  if (in_array($name, $this
    ->getBlacklist())) {
    if ($data) {
      $this->secondaryStorage
        ->write($name, $data);
    }
    return NULL;
  }
  elseif (in_array($name, $this
    ->getGraylist())) {
    if (!$this->configuration['graylist_skip_equal'] || !$this->source || $this->source
      ->read($name) != $data) {

      // The configuration is in the graylist but skip-equal is not set or
      // the source does not have the same data, so write to secondary and
      // return source data or null if it doesn't exist in the source.
      if ($data) {
        $this->secondaryStorage
          ->write($name, $data);
      }

      // If the source has it, return that so it doesn't get changed.
      if ($this->source) {
        return $this->source
          ->read($name);
      }
      return NULL;
    }
  }
  if ($this->secondaryStorage
    ->exists($name)) {

    // If the secondary storage has the file but should not then delete it.
    $this->secondaryStorage
      ->delete($name);
  }
  if ($name != 'core.extension') {
    return $data;
  }
  $data['module'] = array_diff_key($data['module'], $this->configuration['module']);
  $data['theme'] = array_diff_key($data['theme'], $this->configuration['theme']);
  return $data;
}