diff --git a/core/.MAINTAINERS.txt.swp b/core/.MAINTAINERS.txt.swp new file mode 100644 index 0000000..7043893 Binary files /dev/null and b/core/.MAINTAINERS.txt.swp differ diff --git a/core/lib/Drupal/Core/Asset/AssetResolver.php b/core/lib/Drupal/Core/Asset/AssetResolver.php index c41e14e..d0f00cf 100644 --- a/core/lib/Drupal/Core/Asset/AssetResolver.php +++ b/core/lib/Drupal/Core/Asset/AssetResolver.php @@ -123,23 +123,9 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) { // order. $options['weight'] += count($css) / 1000; - // 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. - 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; - } + // Local and external files must keep their name as the associative + // key so the same CSS file is not added twice. + $css[$options['data']] = $options; } } } @@ -155,15 +141,23 @@ public function getCssAssets(AttachedAssetsInterface $assets, $optimize) { if ($stylesheet_remove = $theme_info->getStyleSheetsRemove()) { foreach ($css as $key => $options) { if (isset($options['basename']) && isset($stylesheet_remove[$options['basename']])) { - unset($css[$key]); + foreach ($css as $css_path => $item) { + $file_name = end(explode('/', $css_path)); + if ($file_name == $key) { + unset($css[$css_path]); + } + } } } } // Allow themes to conditionally override CSS files by basename. if ($stylesheet_override = $theme_info->getStyleSheetsOverride()) { foreach ($css as $key => $options) { - if (isset($options['basename']) && isset($stylesheet_override[$options['basename']])) { - $css[$key]['data'] = $stylesheet_override[$options['basename']]; + foreach ($css as $css_path => $item) { + $file_name = end(explode('/', $css_path)); + if ($file_name == $key) { + $css[$css_path]['data'] = $stylesheet_override[$options['basename']]; + } } } } diff --git a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php index a52db9b..37b07b9 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('common_test/files/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); 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: {}