diff --git a/core/lib/Drupal/Core/Extension/ThemeInstaller.php b/core/lib/Drupal/Core/Extension/ThemeInstaller.php index d141d82..e93777b 100644 --- a/core/lib/Drupal/Core/Extension/ThemeInstaller.php +++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php @@ -139,9 +139,10 @@ public function install(array $theme_list, $install_dependencies = TRUE) { } while (list($theme) = each($theme_list)) { - $module_dependencies = isset($theme_data[$theme]->requires['modules']) ? $theme_data[$theme]->requires['modules'] : []; - $this->moduleInstaller->install($module_dependencies); - unset($theme_data[$theme]->requires['modules']); + $module_dependencies = array_diff_key($theme_data[$theme]->requires, $theme_data); + $theme_dependencies = array_diff_key($theme_data[$theme]->requires, $module_dependencies); + $this->getModuleInstaller()->install(array_keys($module_dependencies)); + $theme_data[$theme]->requires = $theme_dependencies; // Add dependencies to the list. The new themes will be processed as // the while loop continues. diff --git a/core/modules/system/src/Tests/Extension/ThemeInstallerTest.php b/core/modules/system/src/Tests/Extension/ThemeInstallerTest.php index 6fe81f7..8451ee4 100644 --- a/core/modules/system/src/Tests/Extension/ThemeInstallerTest.php +++ b/core/modules/system/src/Tests/Extension/ThemeInstallerTest.php @@ -9,7 +9,8 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Extension\ExtensionNameLengthException; -use Drupal\simpletest\KernelTestBase; +use Drupal\KernelTests\KernelTestBase; +use Drupal\test_theme_dependency\Service; /** * Tests installing and uninstalling of themes. @@ -25,14 +26,16 @@ class ThemeInstallerTest extends KernelTestBase { */ public static $modules = array('system'); - public function containerBuild(ContainerBuilder $container) { - parent::containerBuild($container); + public function register(ContainerBuilder $container) { + parent::register($container); + // Some test methods involve ModuleHandler operations, which attempt to // rebuild and dump routes. $container ->register('router.dumper', 'Drupal\Core\Routing\NullMatcherDumper'); } + protected function setUp() { parent::setUp(); $this->installConfig(array('system')); @@ -352,6 +355,15 @@ function testThemeInfoAlter() { $this->assertFalse(isset($system_list[$name]->info['regions']['test_region'])); } + public function testThemeWithModuleDependency() { + $this->assertFalse($this->moduleHandler()->moduleExists('test_theme_dependency')); + $this->themeInstaller()->install(['test_theme_module_dependency']); + $this->assertTrue($this->moduleHandler()->moduleExists('test_theme_dependency')); + + $service = \Drupal::service('test_theme_dependency.service'); + $this->assertInstanceOf(Service::class, $service); + } + /** * Returns the theme handler service. * diff --git a/core/modules/system/tests/themes/test_theme_module_dependency/test_theme_dependency/src/Service.php b/core/modules/system/tests/themes/test_theme_module_dependency/test_theme_dependency/src/Service.php new file mode 100644 index 0000000..6313712 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_module_dependency/test_theme_dependency/src/Service.php @@ -0,0 +1,12 @@ +