diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index 1b68a40..89cee73 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -460,12 +460,9 @@ public function checkConfigurationToInstall($type, $name) { if (!empty($invalid_default_config)) { $missing = []; foreach ($missing_dependencies as $dependent => $dependencies) { - $missing = array_merge($missing, $dependencies); + $missing[$dependent] = $dependencies; } - if ($missing) { - $missing = array_unique($missing); - } - throw UnmetDependenciesException::create($name, $invalid_default_config, $missing); + throw UnmetDependenciesException::create($name, array_unique($missing)); } // Install profiles can not have config clashes. Configuration that @@ -501,7 +498,7 @@ public function checkConfigurationToInstall($type, $name) { protected function findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = [], array &$missing_dependencies = []) { $config_to_create = $this->getConfigToCreate($storage, StorageInterface::DEFAULT_COLLECTION, '', $profile_storages); $all_config = array_merge($this->configFactory->listAll(), array_keys($config_to_create)); - return array_filter(array_keys($config_to_create), function($config_name) use ($enabled_extensions, $all_config, $config_to_create, $missing_dependencies) { + return array_filter(array_keys($config_to_create), function($config_name) use ($enabled_extensions, $all_config, $config_to_create, &$missing_dependencies) { $missing = $this->getMissingDependencies($config_name, $config_to_create[$config_name], $enabled_extensions, $all_config); if ($missing) { $missing_dependencies[$config_name] = $missing; diff --git a/core/lib/Drupal/Core/Config/UnmetDependenciesException.php b/core/lib/Drupal/Core/Config/UnmetDependenciesException.php index fd2b63f..5d0cfb1 100644 --- a/core/lib/Drupal/Core/Config/UnmetDependenciesException.php +++ b/core/lib/Drupal/Core/Config/UnmetDependenciesException.php @@ -53,12 +53,10 @@ public function getExtension() { * @return string */ public function getTranslatedMessage(TranslationInterface $string_translation, $extension) { - return $string_translation->formatPlural( - count($this->getConfigObjects()), - 'Unable to install @extension, %config_names has unmet dependencies.', - 'Unable to install @extension, %config_names have unmet dependencies.', + return $string_translation->translate( + 'Unable to install @extension due to unmet dependencies: @config_names', [ - '%config_names' => implode(', ', $this->getConfigObjects()), + '@config_names' => self::formatConfigObjectList($this->configObjects), '@extension' => $extension, ] ); @@ -70,18 +68,16 @@ public function getTranslatedMessage(TranslationInterface $string_translation, $ * @param $extension * The name of the extension that is being installed. * @param array $config_objects - * A list of configuration object names that have unmet dependencies - * @param array $missing_dependencies - * (optional) The list of missing dependencies. + * A list of configuration keyed by configuration name, with unmet + * dependencies as the value. * * @return \Drupal\Core\Config\PreExistingConfigException */ - public static function create($extension, array $config_objects, array $missing_dependencies = []) { - $message = SafeMarkup::format('Configuration objects (@config_names) provided by @extension have unmet dependencies: @dependencies', + public static function create($extension, array $config_objects) { + $message = SafeMarkup::format('Configuration objects provided by @extension have unmet dependencies: @config_names', array( - '@config_names' => implode(', ', $config_objects), - '@extension' => $extension, - '@dependencies' => implode(', ', $missing_dependencies), + '@config_names' => static::formatConfigObjectList($config_objects), + '@extension' => $extension ) ); $e = new static($message); @@ -90,4 +86,21 @@ public static function create($extension, array $config_objects, array $missing_ return $e; } + /** + * Formats a list of configuration objects. + * + * @param array $config_objects + * A list of configuration object names that have unmet dependencies. + * + * @return string + * The imploded config_objects, formatted in an easy to read string. + */ + protected static function formatConfigObjectList(array $config_objects) { + $list = []; + foreach ($config_objects as $config_object => $missing_dependencies) { + $list[] = $config_object . ' (' . implode(', ', $missing_dependencies) . ')'; + } + return implode(', ', $list); + } + } diff --git a/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php b/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php index 3371198..cfebbb6 100644 --- a/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php +++ b/core/modules/config/src/Tests/ConfigInstallProfileUnmetDependenciesTest.php @@ -90,7 +90,7 @@ public function testInstalled() { else { $this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception thrown'); } - $this->assertErrorLogged('Configuration objects (system.action.user_block_user_action) provided by user have unmet dependencies in'); + $this->assertErrorLogged('Configuration objects provided by user have unmet dependencies: system.action.user_block_user_action (action)'); } } diff --git a/core/modules/config/src/Tests/ConfigInstallWebTest.php b/core/modules/config/src/Tests/ConfigInstallWebTest.php index 083b123..6c3be10 100644 --- a/core/modules/config/src/Tests/ConfigInstallWebTest.php +++ b/core/modules/config/src/Tests/ConfigInstallWebTest.php @@ -180,7 +180,7 @@ public function testUnmetDependenciesInstall() { // not depend on config_test and order is important. $this->drupalPostForm('admin/modules', array('modules[Testing][config_test][enable]' => TRUE), t('Install')); $this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Install')); - $this->assertRaw('Unable to install Config install dependency test, config_other_module_config_test.weird_simple_config, config_test.dynamic.other_module_test_with_dependency have unmet dependencies.'); + $this->assertRaw('Unable to install Config install dependency test due to unmet dependencies: config_test.dynamic.other_module_test_with_dependency (config_other_module_config_test)'); $this->drupalPostForm('admin/modules', array('modules[Testing][config_other_module_config_test][enable]' => TRUE), t('Install')); $this->drupalPostForm('admin/modules', array('modules[Testing][config_install_dependency_test][enable]' => TRUE), t('Install')); diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index 4258f80..c2b53ad 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -830,7 +830,7 @@ protected function assertErrorLogged($error_message) { } $content = file_get_contents($error_log_filename); - $rows = explode(PHP_EOL, $content); + $rows = explode(PHP_EOL, $content); // We iterate over the rows in order to be able to remove the logged error // afterwards.