diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 1cffc5c..cfd7e65 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -70,9 +70,17 @@ public function __construct(ConfigFactoryInterface $config_factory, StorageInter } /** - * {@inheritdoc} + * Gather default configuration to install. + * + * @param string $type + * Type of extension to install. + * @param string $name + * Name of extension to install. + * + * @return + * Array with list of configuration keys to install. */ - public function installDefaultConfig($type, $name) { + protected function gatherDefaultConfig($type, $name) { // Get all default configuration owned by this extension. $source_storage = new ExtensionInstallStorage($this->activeStorage); $config_to_install = $source_storage->listAll($name . '.'); @@ -103,17 +111,19 @@ public function installDefaultConfig($type, $name) { $config_to_install = array_merge($config_to_install, $other_module_config); } + return $config_to_install; + } + + /** + * {@inheritdoc} + */ + public function installDefaultConfig($type, $name) { + $config_to_install = $this->gatherDefaultConfig($type, $name); if (!empty($config_to_install)) { $old_state = $this->configFactory->getOverrideState(); $this->configFactory->setOverrideState(FALSE); foreach ($config_to_install as $config_name) { - // Only import new config. - if ($this->activeStorage->exists($config_name)) { - drupal_set_message(t('Active configuration with the name %config_name already exists therefore can not install the default configuration with the same name from %extension.', array('%config_name' => $config_name, '%extension' => $name)), 'warning'); - continue; - } - $new_config = new Config($config_name, $this->activeStorage, $this->eventDispatcher, $this->typedConfig); $data = $source_storage->read($config_name); if ($data !== FALSE) { @@ -134,4 +144,28 @@ public function installDefaultConfig($type, $name) { } } + /** + * Validate default configuration before installation. + * + * @param string $type + * Type of extension to install. + * @param string $name + * Name of extension to install. + * + * @return bool + * Whether all the default configuration of this module can be installed. + * If any of the default configuration already exists in the system, returns + * FALSE. + */ + public function validatePreInstall($type, $name) { + $config_to_install = $this->gatherDefaultConfig($type, $name); + foreach ($config_to_install as $config_name) { + if ($this->activeStorage->exists($config_name)) { + drupal_set_message(t('Active configuration with the name %config_name already exists therefore can not install the default configuration from with the same name from %extension.', array('%config_name' => $config_name, '%extension' => $name)), 'warning'); + return FALSE; + } + } + return TRUE; + } + } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index 001e278..412a54c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -563,6 +563,13 @@ public function install(array $module_list, $enable_dependencies = TRUE) { ))); } + // Validate default configuration of this module. Bail if unable to + // install. Should not continue installing more modules because those + // may depend on this one. + if (!\Drupal::service('config.installer')->validatePreInstall('module', $module)) { + break; + } + $module_config ->set("enabled.$module", 0) ->set('enabled', module_config_sort($module_config->get('enabled')))