CoreExtensionFilter.php

  1. 8.0.x lib/Drush/Config/CoreExtensionFilter.php
  2. master lib/Drush/Config/CoreExtensionFilter.php

Definition of Drush\Config\StorageFilter.

Namespace

Drush\Config

Classes

Namesort descending Description
CoreExtensionFilter This filter adjusts the data going to and coming from the core.extension configuration object.

File

lib/Drush/Config/CoreExtensionFilter.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Definition of Drush\Config\StorageFilter.
  5. */
  6. namespace Drush\Config;
  7. use Drupal\Core\Config\StorageInterface;
  8. /**
  9. * This filter adjusts the data going to and coming from
  10. * the core.extension configuration object.
  11. *
  12. * Modules named in this list are ignored during config-import
  13. * and config-export operations. What this means in practical terms is:
  14. *
  15. * * During a 'read' operation, if a named module is enabled in the
  16. * active configuration, then it will remain enabled after the
  17. * import. If it is disabled in the active configuration, then it
  18. * will remain disabled. The value from the data being imported
  19. * is ignored.
  20. *
  21. * * During a 'write' operation, if a named module is enabled in
  22. * the configuration already written out on the target storage
  23. * object, then it will remain enabled. If it is disabled in
  24. * the previously-exported data, then it will remain disabled. If
  25. * there is no existing export (first-time export), then all of
  26. * the named modules will be excluded (disabled) from the export.
  27. * The current enabled / disabled state of the module in the
  28. * active configuration is ignored.
  29. *
  30. * The data from core.extension looks like this:
  31. *
  32. * module:
  33. * modulename: weight
  34. * theme:
  35. * themename: weight
  36. *
  37. * The "adjustments" lists is just an array where the values
  38. * are the module names to exclude from import / export, as
  39. * described above.
  40. */
  41. class CoreExtensionFilter implements StorageFilter {
  42. protected $adjustments;
  43. function __construct($adjustments = array()) {
  44. $this->adjustments = $adjustments;
  45. }
  46. public function filterRead($name, $data) {
  47. if ($name != 'core.extension') {
  48. return $data;
  49. }
  50. $active_storage = \Drupal::service('config.storage');
  51. return $this->filterOutIgnored($data, $active_storage->read($name));
  52. }
  53. public function filterWrite($name, array $data, StorageInterface $storage) {
  54. if ($name != 'core.extension') {
  55. return $data;
  56. }
  57. $originalData = $storage->read($name);
  58. return $this->filterOutIgnored($data, $storage->read($name));
  59. }
  60. protected function filterOutIgnored($data, $originalData) {
  61. foreach($this->adjustments as $module) {
  62. if (is_array($originalData) && array_key_exists($module, $originalData['module'])) {
  63. $data['module'][$module] = $originalData['module'][$module];
  64. }
  65. else {
  66. unset($data['module'][$module]);
  67. }
  68. }
  69. return $data;
  70. }
  71. }