Skip to content

Commit

Permalink
Close #3588 Allow newly enabled module config to be overridden. (#3589)
Browse files Browse the repository at this point in the history
  • Loading branch information
trackleft authored and joeparsons committed Aug 16, 2024
1 parent 866fab9 commit 7abdf7c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,20 @@ 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.
$owner = $lister->getConfigProvider($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 : [];
Expand Down
28 changes: 28 additions & 0 deletions modules/custom/az_core/tests/src/Functional/ConfigOverrideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

}

0 comments on commit 7abdf7c

Please sign in to comment.