From 1d8712ff746ac594deef156d1640aa688d584173 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Wed, 9 Oct 2019 10:59:35 +0100
Subject: [PATCH] Issue #3079029 by bircher, ricardoamaro, catch, wouter.adem,
 marcvangend, alexpott: Move module config exclusion from config_environment
 to core.services

---
 .../scaffold/files/example.settings.local.php | 24 +++++++++++++++++++
 core/core.services.yml                        |  5 ++++
 .../ExcludedModulesEventSubscriber.php        |  2 +-
 .../install/system.menu.exclude_test.yml      |  0
 .../system.menu.indirect_exclude_test.yml     |  0
 .../config_exclude_test.info.yml              |  1 -
 .../config_environment.services.yml           |  6 -----
 .../ExcludedModulesEventSubscriberTest.php    |  3 +--
 sites/example.settings.local.php              | 24 +++++++++++++++++++
 9 files changed, 55 insertions(+), 10 deletions(-)
 rename core/{modules/config_environment/src => lib/Drupal/Core}/EventSubscriber/ExcludedModulesEventSubscriber.php (99%)
 rename core/modules/{config_environment => config}/tests/config_exclude_test/config/install/system.menu.exclude_test.yml (100%)
 rename core/modules/{config_environment => config}/tests/config_exclude_test/config/install/system.menu.indirect_exclude_test.yml (100%)
 rename core/modules/{config_environment => config}/tests/config_exclude_test/config_exclude_test.info.yml (59%)
 delete mode 100644 core/modules/config_environment/config_environment.services.yml
 rename core/{modules/config_environment/tests/src/Kernel/EventSubscriber => tests/Drupal/KernelTests/Core/Config}/ExcludedModulesEventSubscriberTest.php (97%)

diff --git a/core/assets/scaffold/files/example.settings.local.php b/core/assets/scaffold/files/example.settings.local.php
index 4a40a1318b47..520cb4acd5fa 100644
--- a/core/assets/scaffold/files/example.settings.local.php
+++ b/core/assets/scaffold/files/example.settings.local.php
@@ -129,3 +129,27 @@
  * directory.
  */
 $settings['skip_permissions_hardening'] = TRUE;
+
+/**
+ * Exclude modules from configuration synchronisation.
+ *
+ * On config export sync, no config or dependent config of any excluded module
+ * is exported. On config import sync, any config of any installed excluded
+ * module is ignored. In the exported configuration, it will be as if the
+ * excluded module had never been installed. When syncing configuration, if an
+ * excluded module is already installed, it will not be uninstalled by the
+ * configuration synchronisation, and dependent configuration will remain
+ * intact. This affects only configuration synchronisation; single import and
+ * export of configuration are not affected.
+ *
+ * Drupal does not validate or sanity check the list of excluded modules. For
+ * instance, it is your own responsibility to never exclude required modules,
+ * because it would mean that the exported configuration can not be imported
+ * anymore.
+ *
+ * This is an advanced feature and using it means opting out of some of the
+ * guarantees the configuration synchronisation provides. It is not recommended
+ * to use this feature with modules that affect Drupal in a major way such as
+ * the language or field module.
+ */
+# $settings['config_exclude_modules'] = ['devel', 'stage_file_proxy'];
diff --git a/core/core.services.yml b/core/core.services.yml
index e7378c6abf11..091289c2d265 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1280,6 +1280,11 @@ services:
     tags:
       - { name: event_subscriber }
     arguments: ['@config.manager', '@config.storage', '@config.storage.snapshot']
+  config_exclude_modules_subscriber:
+    class: Drupal\Core\EventSubscriber\ExcludedModulesEventSubscriber
+    arguments: ['@config.storage', '@settings', '@config.manager']
+    tags:
+      - { name: event_subscriber }
   exception.needs_installer:
     class: Drupal\Core\EventSubscriber\ExceptionDetectNeedsInstallSubscriber
     arguments: ['@database']
diff --git a/core/modules/config_environment/src/EventSubscriber/ExcludedModulesEventSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php
similarity index 99%
rename from core/modules/config_environment/src/EventSubscriber/ExcludedModulesEventSubscriber.php
rename to core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php
index 90a81de16e7f..a81f3e02a8cd 100644
--- a/core/modules/config_environment/src/EventSubscriber/ExcludedModulesEventSubscriber.php
+++ b/core/lib/Drupal/Core/EventSubscriber/ExcludedModulesEventSubscriber.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\config_environment\EventSubscriber;
+namespace Drupal\Core\EventSubscriber;
 
 use Drupal\Core\Config\ConfigManagerInterface;
 use Drupal\Core\Config\StorageInterface;
diff --git a/core/modules/config_environment/tests/config_exclude_test/config/install/system.menu.exclude_test.yml b/core/modules/config/tests/config_exclude_test/config/install/system.menu.exclude_test.yml
similarity index 100%
rename from core/modules/config_environment/tests/config_exclude_test/config/install/system.menu.exclude_test.yml
rename to core/modules/config/tests/config_exclude_test/config/install/system.menu.exclude_test.yml
diff --git a/core/modules/config_environment/tests/config_exclude_test/config/install/system.menu.indirect_exclude_test.yml b/core/modules/config/tests/config_exclude_test/config/install/system.menu.indirect_exclude_test.yml
similarity index 100%
rename from core/modules/config_environment/tests/config_exclude_test/config/install/system.menu.indirect_exclude_test.yml
rename to core/modules/config/tests/config_exclude_test/config/install/system.menu.indirect_exclude_test.yml
diff --git a/core/modules/config_environment/tests/config_exclude_test/config_exclude_test.info.yml b/core/modules/config/tests/config_exclude_test/config_exclude_test.info.yml
similarity index 59%
rename from core/modules/config_environment/tests/config_exclude_test/config_exclude_test.info.yml
rename to core/modules/config/tests/config_exclude_test/config_exclude_test.info.yml
index 6ee30864798c..b84feef93aa3 100644
--- a/core/modules/config_environment/tests/config_exclude_test/config_exclude_test.info.yml
+++ b/core/modules/config/tests/config_exclude_test/config_exclude_test.info.yml
@@ -1,4 +1,3 @@
-# @todo: Move this test module under the config module in #3079029.
 name: 'Configuration Module Exclude Test'
 type: module
 package: Testing
diff --git a/core/modules/config_environment/config_environment.services.yml b/core/modules/config_environment/config_environment.services.yml
deleted file mode 100644
index 857f3eda8c6d..000000000000
--- a/core/modules/config_environment/config_environment.services.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-services:
-  config_environment.excluded_modules.event_subscriber:
-    class: Drupal\config_environment\EventSubscriber\ExcludedModulesEventSubscriber
-    arguments: ['@config.storage', '@settings', '@config.manager']
-    tags:
-      - { name: event_subscriber }
diff --git a/core/modules/config_environment/tests/src/Kernel/EventSubscriber/ExcludedModulesEventSubscriberTest.php b/core/tests/Drupal/KernelTests/Core/Config/ExcludedModulesEventSubscriberTest.php
similarity index 97%
rename from core/modules/config_environment/tests/src/Kernel/EventSubscriber/ExcludedModulesEventSubscriberTest.php
rename to core/tests/Drupal/KernelTests/Core/Config/ExcludedModulesEventSubscriberTest.php
index 8e7f0638fc65..10e73cee9606 100644
--- a/core/modules/config_environment/tests/src/Kernel/EventSubscriber/ExcludedModulesEventSubscriberTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ExcludedModulesEventSubscriberTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Drupal\Tests\config_environment\Kernel\EventSubscriber;
+namespace Drupal\KernelTests\Core\Config;
 
 use Drupal\KernelTests\KernelTestBase;
 
@@ -16,7 +16,6 @@ class ExcludedModulesEventSubscriberTest extends KernelTestBase {
    */
   protected static $modules = [
     'system',
-    'config_environment',
     'config_test',
     'config_exclude_test',
   ];
diff --git a/sites/example.settings.local.php b/sites/example.settings.local.php
index 4a40a1318b47..520cb4acd5fa 100644
--- a/sites/example.settings.local.php
+++ b/sites/example.settings.local.php
@@ -129,3 +129,27 @@
  * directory.
  */
 $settings['skip_permissions_hardening'] = TRUE;
+
+/**
+ * Exclude modules from configuration synchronisation.
+ *
+ * On config export sync, no config or dependent config of any excluded module
+ * is exported. On config import sync, any config of any installed excluded
+ * module is ignored. In the exported configuration, it will be as if the
+ * excluded module had never been installed. When syncing configuration, if an
+ * excluded module is already installed, it will not be uninstalled by the
+ * configuration synchronisation, and dependent configuration will remain
+ * intact. This affects only configuration synchronisation; single import and
+ * export of configuration are not affected.
+ *
+ * Drupal does not validate or sanity check the list of excluded modules. For
+ * instance, it is your own responsibility to never exclude required modules,
+ * because it would mean that the exported configuration can not be imported
+ * anymore.
+ *
+ * This is an advanced feature and using it means opting out of some of the
+ * guarantees the configuration synchronisation provides. It is not recommended
+ * to use this feature with modules that affect Drupal in a major way such as
+ * the language or field module.
+ */
+# $settings['config_exclude_modules'] = ['devel', 'stage_file_proxy'];
-- 
GitLab