From 7abdf7c21c4186dfc24ac51d578f1a25cd9a75f5 Mon Sep 17 00:00:00 2001 From: Chris Green Date: Fri, 2 Aug 2024 10:21:51 -0700 Subject: [PATCH] Close #3588 Allow newly enabled module config to be overridden. (#3589) --- .../QuickstartConfigProvider.php | 8 +++++- .../src/Functional/ConfigOverrideTest.php | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/custom/az_core/src/Plugin/ConfigProvider/QuickstartConfigProvider.php b/modules/custom/az_core/src/Plugin/ConfigProvider/QuickstartConfigProvider.php index d41e408563..8d2b0a2d73 100644 --- a/modules/custom/az_core/src/Plugin/ConfigProvider/QuickstartConfigProvider.php +++ b/modules/custom/az_core/src/Plugin/ConfigProvider/QuickstartConfigProvider.php @@ -262,7 +262,6 @@ protected function canOverride($name) { $lister = \Drupal::service('config_update.config_list'); /** @var \Drupal\config_update\ConfigDiffer $differ */ $differ = \Drupal::service('config_update.config_diff'); - // Read active config value for name. $active = $this->getActiveStorages()->read($name); // Find out which module owns the configuration and load the snapshot value. @@ -270,6 +269,13 @@ protected function canOverride($name) { if (!empty($owner[1])) { $snapshot_storage = $this->getConfigSnapshotStorage(ConfigSyncSnapshotterInterface::CONFIG_SNAPSHOT_SET, $owner[0], $owner[1]); $snap = $snapshot_storage->read($name); + // StorageInterface::read() returns FALSE if the config does not exist. + // In this case, we can assume that the configuration is not customized + // because it is not present in the snapshot, likely because the module + // is newly installed. + if ($snap === FALSE) { + return TRUE; + } } // Guard against missing items. $snap = (!empty($snap)) ? $snap : []; diff --git a/modules/custom/az_core/tests/src/Functional/ConfigOverrideTest.php b/modules/custom/az_core/tests/src/Functional/ConfigOverrideTest.php index 2c58114394..2b2a9d9902 100644 --- a/modules/custom/az_core/tests/src/Functional/ConfigOverrideTest.php +++ b/modules/custom/az_core/tests/src/Functional/ConfigOverrideTest.php @@ -51,4 +51,32 @@ public function testConfigOverride() { $this->assertEquals('shibboleth.arizona.edu', $hostname); } + /** + * Tests a config override was applied successfully after module install. + */ + public function testConfigOverrideAfterInstall() { + // Install the az_mail module. + $this->container->get('module_installer')->install(['az_mail']); + $config = $this->config('smtp.settings'); + $this->assertEquals(TRUE, $config->get('smtp_on')); + $this->assertEquals('email-smtp.us-west-2.amazonaws.com', $config->get('smtp_host')); + $this->assertEquals('', $config->get('smtp_hostbackup')); + $this->assertEquals('2587', $config->get('smtp_port')); + $this->assertEquals('tls', $config->get('smtp_protocol')); + $this->assertEquals(TRUE, $config->get('smtp_autotls')); + $this->assertEquals(30, $config->get('smtp_timeout')); + $this->assertEquals('', $config->get('smtp_username')); + $this->assertEquals('', $config->get('smtp_password')); + $this->assertEquals('', $config->get('smtp_from')); + $this->assertEquals('', $config->get('smtp_fromname')); + $this->assertEquals('', $config->get('smtp_client_hostname')); + $this->assertEquals('', $config->get('smtp_client_helo')); + $this->assertEquals('0', $config->get('smtp_allowhtml')); + $this->assertEquals('', $config->get('smtp_test_address')); + $this->assertEquals('', $config->get('smtp_reroute_address')); + $this->assertEquals(FALSE, $config->get('smtp_debugging')); + $this->assertEquals('php_mail', $config->get('prev_mail_system')); + $this->assertEquals(FALSE, $config->get('smtp_keepalive')); + } + }