diff --git a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php index 94d6e3c6d6..64db0a8ed9 100644 --- a/core/lib/Drupal/Core/Extension/InfoParserDynamic.php +++ b/core/lib/Drupal/Core/Extension/InfoParserDynamic.php @@ -131,7 +131,6 @@ public function parse($filename) { if (!empty($non_machine_name_dependencies)) { throw new InfoParserException("Theme module dependencies must be machine names (only underscores, digits, and lowercase letters). At least one dependency declared by {$parsed_info['name']} is not in machine name format: " . implode(',', $non_machine_name_dependencies)); } - } } return $parsed_info; diff --git a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php index d6b13be8c0..ca42313926 100644 --- a/core/lib/Drupal/Core/Extension/ThemeExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ThemeExtensionList.php @@ -142,14 +142,20 @@ protected function doList() { $this->fillInSubThemeData($themes, $sub_themes); foreach ($themes as $key => $theme) { - // After $theme is processed by buildModuleDependencies(), there is a + // After $theme is processed by buildModuleDependencies(), there can be a // `$theme->requires` array containing both module and base theme // dependencies. The module dependencies are copied to their own property // so they are available to operations specific to module dependencies. - if (!isset($theme->requires)) { + if (isset($theme->requires)) { + $theme->module_dependencies = isset($theme->requires) ? array_diff_key($theme->requires, $themes) : []; + } + else { + // Even if no requirements are specified, the theme installation process + // expects the presence of the `requires` and `module_dependencies` + // properties, so they should be initialized here as empty arrays. $theme->requires = []; + $theme->module_dependencies = []; } - $themes[$key]->module_dependencies = isset($theme->requires) ? array_diff_key($theme->requires, $themes) : []; } return $themes; } diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php index 2e8c9ce1ca..c0ada9e028 100644 --- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php @@ -534,4 +534,94 @@ public function testUnparsableCoreVersionRequirement() { $this->infoParser->parse(vfsStream::url('modules/fixtures/unparsable_core_version_requirement.info.txt')); } + /** + * Tests theme dependencies not in machine name format. + * + * @param string $theme_yml + * YML of a theme depending on modules. + * @param string $exception_message + * The expected exception message. + * + * @dataProvider providerTestUnparsableThemeModuleDependency + */ + public function testUnparsableThemeModuleDependency($theme_yml, $exception_message) { + vfsStream::setup('modules'); + vfsStream::create([ + 'fixtures' => [ + 'unparsable_module_dependency.info.txt' => $theme_yml, + ], + ]); + $this->expectException(InfoParserException::class); + $this->expectExceptionMessage($exception_message); + $this->infoParser->parse(vfsStream::url('modules/fixtures/unparsable_module_dependency.info.txt')); + } + + /** + * Data provider for testUnparsableThemeModuleDependency(). + */ + public function providerTestUnparsableThemeModuleDependency() { + $has_version_constraints = <<4.1) +UNPARSABLE; + + $has_project_prefix = << [ + $has_version_constraints, + 'Theme module dependencies must be machine names (only underscores, digits, and lowercase letters). At least one dependency declared by Test Theme Depending on Modules is not in machine name format: module_with_some_version_metadata (>4.1)', + ], + 'has_project_prefix' => [ + $has_project_prefix, + 'Theme module dependencies must be machine names (only underscores, digits, and lowercase letters). At least one dependency declared by Test Theme Depending on Modules is not in machine name format: drupal::module_with_a_project_prefix', + ], + 'has_a_space' => [ + $has_a_space, + 'Theme module dependencies must be machine names (only underscores, digits, and lowercase letters). At least one dependency declared by Test Theme Depending on Modules is not in machine name format: apparently_i_have_a space', + ], + 'has_capital' => [ + $has_capital, + 'Theme module dependencies must be machine names (only underscores, digits, and lowercase letters). At least one dependency declared by Test Theme Depending on Modules is not in machine name format: capitalLetters', + ], + ]; + } + }