diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 8c573bbc09557c440cefdae48e360c6cf7001474..3363efc5188311c69eb6f134e7464c1d4d450830 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -198,8 +198,10 @@ public function listInfo() { * {@inheritdoc} */ public function addTheme(Extension $theme) { - foreach ($theme->info['libraries'] as $library => $name) { - $theme->libraries[$library] = $name; + if (!empty($theme->info['libraries'])) { + foreach ($theme->info['libraries'] as $library => $name) { + $theme->libraries[$library] = $name; + } } if (isset($theme->info['engine'])) { $theme->engine = $theme->info['engine']; diff --git a/core/modules/system/tests/themes/test_theme_libraries_empty/test_theme_libraries_empty.info.yml b/core/modules/system/tests/themes/test_theme_libraries_empty/test_theme_libraries_empty.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..bfe8a93f2f7d8f5a54e31b36b1f59144fd1d6e95 --- /dev/null +++ b/core/modules/system/tests/themes/test_theme_libraries_empty/test_theme_libraries_empty.info.yml @@ -0,0 +1,8 @@ +name: 'Test theme libraries empty' +type: theme +description: 'Test theme with empty libraries in theme.info.yml' +version: VERSION +base theme: classy +core: 8.x +libraries: + diff --git a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php index 4653f1371e2583aa56d47465ad63fdc7934699cf..27a9702c6599c370b1fc9b7779f2080845e916d7 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php @@ -137,6 +137,20 @@ public function testRebuildThemeData() { $this->assertEquals(array('seven/global-styling'), $info->info['libraries']); } + /** + * Tests empty libraries in theme.info.yml file. + */ + public function testThemeLibrariesEmpty() { + $theme = new Extension($this->root, 'theme', '/core/modules/system/tests/themes/test_theme_libraries_empty', 'test_theme_libraries_empty.info.yml'); + try { + $this->themeHandler->addTheme($theme); + $this->assertTrue(TRUE, 'Empty libraries key in theme.info.yml does not cause PHP warning'); + } + catch (\Exception $e) { + $this->fail('Empty libraries key in theme.info.yml causes PHP warning.'); + } + } + /** * Tests rebuild the theme data with theme parents. */