diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php index c41e14e..1301da9 100644 --- a/core/lib/Drupal/Core/Asset/AssetResolver.php +++ b/core/lib/Drupal/Core/Asset/AssetResolver.php @@ -126,13 +126,13 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) { // Add the data to the CSS array depending on the type. switch ($options['type']) { case 'file': - // Local CSS files are keyed by basename; if a file with the same - // basename is added more than once, it gets overridden. - // By default, take over the filename as basename. + // Local CSS files are keyed by library and the file basename. + // Same basename cannot be used multiple times in a single + // library. if (!isset($options['basename'])) { $options['basename'] = drupal_basename($options['data']); } - $css[$options['basename']] = $options; + $css[$library . '/' . $options['basename']] = $options; break; default: @@ -259,9 +259,23 @@ public function getJsAssets(AttachedAssetsInterface $assets, $optimize) { // order. $options['weight'] += count($javascript) / 1000; - // Local and external files must keep their name as the associative - // key so the same JavaScript file is not added twice. - $javascript[$options['data']] = $options; + // Add the data to the CSS array depending on the type. + switch ($options['type']) { + case 'file': + // Local Javascript files are keyed by library and basename. + // Same basename cannot be used multiple times in a single + // library. + if (!isset($options['basename'])) { + $options['basename'] = drupal_basename($options['data']); + } + $javascript[$library . '/' . $options['basename']] = $options; + break; + + default: + // External files are keyed by their full URI, so the same + // Javascript file is not added twice. + $javascript[$options['data']] = $options; + } } } } diff --git a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php index aeb8846..3b1361d 100644 --- a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php @@ -99,13 +99,13 @@ public function testChanges() { $active_theme = $this->themeManager->getActiveTheme(); // Make sure we are not testing the wrong theme. $this->assertEqual('test_theme', $active_theme->getName()); - $this->assertEqual(['classy/base'], $active_theme->getLibraries()); + $this->assertEqual(['classy/base', 'test_theme/global-styling'], $active_theme->getLibraries()); // @see theme_test_system_info_alter() $this->state->set('theme_test.modify_info_files', TRUE); drupal_flush_all_caches(); $active_theme = $this->themeManager->getActiveTheme(); - $this->assertEqual(['classy/base', 'core/backbone'], $active_theme->getLibraries()); + $this->assertEqual(['classy/base', 'test_theme/global-styling', 'core/backbone'], $active_theme->getLibraries()); } } diff --git a/core/modules/system/src/Tests/Theme/ThemeTest.php b/core/modules/system/src/Tests/Theme/ThemeTest.php index 4573d01..9aaa8e9 100644 --- a/core/modules/system/src/Tests/Theme/ThemeTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeTest.php @@ -181,6 +181,28 @@ function testCSSOverride() { } /** + * Ensures that test theme loads an CSS file named same as in parent theme. It + * should load both files. + * + * @see test_theme.info.yml + * @see test_theme.libraries.yml + */ + function testCSSWithSameNameAsInParent() { + // Take off css preprocessing + $config = $this->config('system.performance'); + $config->set('css.preprocess', 0); + $config->save(); + + // Reuse the same page as in testPreprocessForSuggestions(). Request page + // and ensure that parent and test theme's same named CSS file gets loaded. + $this->drupalGet('theme-test/suggestion'); + $classy_layout_css_url = drupal_get_path('theme', 'classy') .'/css/layout.css'; + $theme_test_layout_css_url = drupal_get_path('theme', 'test_theme') .'/css/layout.css'; + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '" . $classy_layout_css_url . "')]")), $classy_layout_css_url . " found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '" . $theme_test_layout_css_url . "')]")), $theme_test_layout_css_url . " found"); + } + + /** * Ensures a themes template is overrideable based on the 'template' filename. */ function testTemplateOverride() { diff --git a/core/modules/system/tests/themes/test_theme/css/layout.css b/core/modules/system/tests/themes/test_theme/css/layout.css new file mode 100644 index 0000000..db5765f --- /dev/null +++ b/core/modules/system/tests/themes/test_theme/css/layout.css @@ -0,0 +1,7 @@ + +/** + * This file is for testing CSS file named same as in parent theme through + * *.libraries.yml file. + * Used in + * No contents are necessary. + */ diff --git a/core/modules/system/tests/themes/test_theme/test_theme.info.yml b/core/modules/system/tests/themes/test_theme/test_theme.info.yml index 9eebc90..5000e74 100644 --- a/core/modules/system/tests/themes/test_theme/test_theme.info.yml +++ b/core/modules/system/tests/themes/test_theme/test_theme.info.yml @@ -14,6 +14,8 @@ description: 'Theme for testing the theme system' version: VERSION base theme: classy core: 8.x +libraries: + - test_theme/global-styling stylesheets-remove: - system.module.css regions: diff --git a/core/modules/system/tests/themes/test_theme/test_theme.libraries.yml b/core/modules/system/tests/themes/test_theme/test_theme.libraries.yml new file mode 100644 index 0000000..ed21a2d --- /dev/null +++ b/core/modules/system/tests/themes/test_theme/test_theme.libraries.yml @@ -0,0 +1,5 @@ +global-styling: + version: VERSION + css: + theme: + css/layout.css: {}