diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php index c41e14e..1d43a79 100644 --- a/core/lib/Drupal/Core/Asset/AssetResolver.php +++ b/core/lib/Drupal/Core/Asset/AssetResolver.php @@ -123,23 +123,19 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) { // order. $options['weight'] += count($css) / 1000; - // Add the data to the CSS array depending on the type. + // Local and external files must keep their name as the associative + // key so the same CSS file is not added twice. Depending on the type, + // some options may need some processing. 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 need the basename to be saved because it is + // used for overriding and removing stylesheets. if (!isset($options['basename'])) { $options['basename'] = drupal_basename($options['data']); } - $css[$options['basename']] = $options; break; - - default: - // External files are keyed by their full URI, so the same CSS - // file is not added twice. - $css[$options['data']] = $options; } + $css[$options['data']] = $options; } } } diff --git a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php index a52db9b..d111f44 100644 --- a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php +++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php @@ -89,7 +89,7 @@ function testAddFiles() { $css = $this->assetResolver->getCssAssets($assets, FALSE); $js = $this->assetResolver->getJsAssets($assets, FALSE)[1]; - $this->assertTrue(array_key_exists('bar.css', $css), 'CSS files are correctly added.'); + $this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/bar.css', $css), 'CSS files are correctly added.'); $this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/foo.js', $js), 'JavaScript files are correctly added.'); $css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css); @@ -470,7 +470,7 @@ function testAddJsFileWithQueryString() { $css = $this->assetResolver->getCssAssets($assets, FALSE); $js = $this->assetResolver->getJsAssets($assets, FALSE)[1]; - $this->assertTrue(array_key_exists('querystring.css?arg1=value1&arg2=value2', $css), 'CSS file with query string is correctly added.'); + $this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2', $css), 'CSS file with query string is correctly added.'); $this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js), 'JavaScript file with query string is correctly added.'); $css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css); diff --git a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php index aeb8846..aa069c5 100644 --- a/core/modules/system/src/Tests/Theme/ThemeInfoTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeInfoTest.php @@ -86,6 +86,10 @@ function testStylesheets() { $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'sub-remove.css')]")), "sub-remove.css not found"); $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-add.sub-remove.css')]")), "base-add.sub-remove.css not found"); $this->assertIdentical(0, count($this->xpath("//link[contains(@href, 'base-override.sub-remove.css')]")), "base-override.sub-remove.css not found"); + + // Verify that CSS files with the same name are loaded from both the base theme and subtheme. + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$base/samename.css')]")), "$base/samename.css found"); + $this->assertIdentical(1, count($this->xpath("//link[contains(@href, '$sub/samename.css')]")), "$sub/samename.css found"); } /** @@ -99,13 +103,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/tests/themes/test_basetheme/test_basetheme.libraries.yml b/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml index 1c72d30..49e4ba1 100644 --- a/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml +++ b/core/modules/system/tests/themes/test_basetheme/test_basetheme.libraries.yml @@ -5,3 +5,4 @@ global-styling: base-add.css: {} base-add.sub-override.css: {} base-add.sub-remove.css: {} + samename.css: {} diff --git a/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml b/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml index efce7ae..931dffe 100644 --- a/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml +++ b/core/modules/system/tests/themes/test_subtheme/test_subtheme.libraries.yml @@ -3,3 +3,4 @@ global-styling: css: base: css/sub-add.css: {} + css/samename.css: {}