You are here

public function SplitFilter::filterRead in Configuration Split 8

1 call to SplitFilter::filterRead()
SplitFilter::filterReadMultiple in src/Plugin/ConfigFilter/SplitFilter.php

File

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

Class

SplitFilter
Provides a SplitFilter.

Namespace

Drupal\config_split\Plugin\ConfigFilter

Code

public function filterRead($name, $data) {
  if ($this->secondaryStorage) {
    if ($alternative = $this->secondaryStorage
      ->read($name)) {
      return $alternative;
    }
  }
  if ($name != 'core.extension') {
    return $data;
  }
  $modules = isset($this->configuration['module']) ? $this->configuration['module'] : [];
  $themes = isset($this->configuration['theme']) ? $this->configuration['theme'] : [];
  if ($this->filtered) {

    // When filtering the 'read' operation, we are about to import the sync
    // configuration. The configuration of the filter is the active config,
    // but we are about to decide which modules should be enabled in addition
    // to the ones defined in the primary storage's 'core.extension'.
    // So we need to read the configuration as it will be imported, as the
    // filter configuration could be split off itself.
    $modules = [];
    $themes = [];
    $updated = $this->filtered
      ->read($this->configuration['config_name']);
    if (is_array($updated)) {
      $modules = isset($updated['module']) ? $updated['module'] : $modules;
      $themes = isset($updated['theme']) ? $updated['theme'] : $themes;
    }
  }
  $data['module'] = array_merge($data['module'], $modules);
  $data['theme'] = array_merge($data['theme'], $themes);

  // Sort the modules.
  $sort_modules = $data['module'];
  uksort($sort_modules, function ($a, $b) use ($sort_modules) {

    // Sort by module weight, this assumes the schema of core.extensions.
    if ($sort_modules[$a] != $sort_modules[$b]) {
      return $sort_modules[$a] > $sort_modules[$b] ? 1 : -1;
    }

    // Or sort by module name.
    return $a > $b ? 1 : -1;
  });
  $data['module'] = $sort_modules;
  return $data;
}