Skip to content
Snippets Groups Projects

Ensure that the list of new config is correct when installing modules

Files
5
+ 40
2
@@ -71,6 +71,24 @@ class ConfigSelector {
*/
protected $messenger;
/**
* Ensures ::selectConfig() has the correct list of configuration.
*
* Prevents multiple triggers of ::setCurrentConfigList() causing the list of
* new configuration to be calculated incorrectly.
*
* Records the name of the module that first triggered
* config_selector_module_preinstall().
*
* @var string
*
* @see \Drupal\config_selector\ConfigSelector::setCurrentConfigList()
* @see \Drupal\config_selector\ConfigSelector::selectConfig()
* @see config_selector_module_preinstall()
* @see config_selector_modules_installed()
*/
private static $modulePreinstallTriggered;
/**
* ConfigSelector constructor.
*
@@ -110,6 +128,13 @@ class ConfigSelector {
* @see config_selector_module_preinstall()
*/
public function setCurrentConfigList($module) {
// This should only trigger once per set of modules passed to the
// ModuleInstaller to install. As service will be rebuild during the module
// install a private static variable is used to store this information.
if (static::$modulePreinstallTriggered !== NULL) {
return $this;
}
static::$modulePreinstallTriggered = $module;
if ($module === 'config_selector') {
// If the Configuration Selector module is being installed, process all
// existing configuration in
@@ -212,13 +237,26 @@ class ConfigSelector {
}
/**
* Selects configuration to enable and disable after installing a module.
* Selects configuration to enable and disable after installing modules.
*
* Ensures config selection works when multiple modules are installed or
* when a module's hook_install() also installs modules.
*
* @param string[] $modules
* The list of modules being installed.
*
* @return $this
*
* @see config_selector_modules_installed()
*/
public function selectConfig() {
public function selectConfigOnInstall(array $modules) {
if (static::$modulePreinstallTriggered !== NULL && !in_array(static::$modulePreinstallTriggered, $modules)) {
return $this;
}
// Reset the flag as we're now selecting config based on the new config that
// has been created.
static::$modulePreinstallTriggered = NULL;
$new_configuration_list = array_diff(
$this->configFactory->listAll(),
$this->state->get('config_selector.current_config_list', [])
Loading