5 * Definition of Drush\Config\StorageFilter.
8 namespace Drush\Config;
10 use Drupal\Core\Config\StorageInterface;
13 * This filter adjusts the data going to and coming from
14 * the core.extension configuration object.
16 * Modules named in this list are ignored during config-import
17 * and config-export operations. What this means in practical terms is:
19 * * During a 'read' operation, if a named module is enabled in the
20 * active configuration, then it will remain enabled after the
21 * import. If it is disabled in the active configuration, then it
22 * will remain disabled. The value from the data being imported
25 * * During a 'write' operation, if a named module is enabled in
26 * the configuration already written out on the target storage
27 * object, then it will remain enabled. If it is disabled in
28 * the previously-exported data, then it will remain disabled. If
29 * there is no existing export (first-time export), then all of
30 * the named modules will be excluded (disabled) from the export.
31 * The current enabled / disabled state of the module in the
32 * active configuration is ignored.
34 * The data from core.extension looks like this:
41 * The "adjustments" lists is just an array where the values
42 * are the module names to exclude from import / export, as
45 class CoreExtensionFilter implements StorageFilter {
47 protected $adjustments;
49 function __construct($adjustments = array()) {
50 $this->adjustments = $adjustments;
53 public function filterRead($name, $data) {
54 if ($name != 'core.extension') {
57 $active_storage = \Drupal::service('config.storage');
58 return $this->filterOutIgnored($data, $active_storage->read($name));
61 public function filterWrite($name, array $data, StorageInterface $storage) {
62 if ($name != 'core.extension') {
65 $originalData = $storage->read($name);
66 return $this->filterOutIgnored($data, $storage->read($name));
69 protected function filterOutIgnored($data, $originalData) {
70 foreach($this->adjustments as $module) {
71 if (is_array($originalData) && array_key_exists($module, $originalData['module'])) {
72 $data['module'][$module] = $originalData['module'][$module];
75 unset($data['module'][$module]);