Version 1
[yaffs-website] / vendor / drush / drush / lib / Drush / Config / CoreExtensionFilter.php
1 <?php
2
3 /**
4  * @file
5  * Definition of Drush\Config\StorageFilter.
6  */
7
8 namespace Drush\Config;
9
10 use Drupal\Core\Config\StorageInterface;
11
12 /**
13  * This filter adjusts the data going to and coming from
14  * the core.extension configuration object.
15  *
16  * Modules named in this list are ignored during config-import
17  * and config-export operations.  What this means in practical terms is:
18  *
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
23  *     is ignored.
24  *
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.
33  *
34  * The data from core.extension looks like this:
35  *
36  * module:
37  *   modulename: weight
38  * theme:
39  *   themename: weight
40  *
41  * The "adjustments" lists is just an array where the values
42  * are the module names to exclude from import / export, as
43  * described above.
44  */
45 class CoreExtensionFilter implements StorageFilter {
46
47   protected $adjustments;
48
49   function __construct($adjustments = array()) {
50     $this->adjustments = $adjustments;
51   }
52
53   public function filterRead($name, $data) {
54     if ($name != 'core.extension') {
55       return $data;
56     }
57     $active_storage = \Drupal::service('config.storage');
58     return $this->filterOutIgnored($data, $active_storage->read($name));
59   }
60
61   public function filterWrite($name, array $data, StorageInterface $storage) {
62     if ($name != 'core.extension') {
63       return $data;
64     }
65     $originalData = $storage->read($name);
66     return $this->filterOutIgnored($data, $storage->read($name));
67   }
68
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];
73       }
74       else {
75         unset($data['module'][$module]);
76       }
77     }
78     return $data;
79
80   }
81 }