diff --git a/core/includes/common.inc b/core/includes/common.inc index edd7c2d..0bc786c 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2601,9 +2601,20 @@ function drupal_add_css($data = NULL, $options = NULL) { // key as $data could be a very long string of CSS. $css[] = $options; break; + + 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($data); + } + $css[$options['basename']] = $options; + break; + default: - // Local and external files must keep their name as the associative key - // so the same CSS file is not be added twice. + // External files are keyed by their full URI, so the same CSS file is + // not added twice. $css[$data] = $options; } } @@ -2641,6 +2652,8 @@ function drupal_add_css($data = NULL, $options = NULL) { * @see drupal_add_css() */ function drupal_get_css($css = NULL, $skip_alter = FALSE) { + global $theme_info; + if (!isset($css)) { $css = drupal_add_css(); } @@ -2653,17 +2666,12 @@ function drupal_get_css($css = NULL, $skip_alter = FALSE) { // Sort CSS items, so that they appear in the correct order. uasort($css, 'drupal_sort_css_js'); - // Remove the overridden CSS files. Later CSS files override former ones. - $previous_item = array(); - foreach ($css as $key => $item) { - if ($item['type'] == 'file') { - // If defined, force a unique basename for this file. - $basename = isset($item['basename']) ? $item['basename'] : drupal_basename($item['data']); - if (isset($previous_item[$basename])) { - // Remove the previous item that shared the same base name. - unset($css[$previous_item[$basename]]); + // Allow themes to conditionally override module CSS files by basename. + if (!empty($theme_info->stylesheets_override)) { + foreach ($css as $key => $options) { + if (isset($options['basename']) && isset($theme_info->stylesheets_override[$options['basename']])) { + $css[$key]['data'] = $theme_info->stylesheets_override[$options['basename']]; } - $previous_item[$basename] = $key; } } diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 3ce399b..e38739e 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -149,6 +149,10 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb // We work it this way so that we can have child themes override parent // theme stylesheets easily. $final_stylesheets = array(); + // List of CSS file basenames to override, pointing to the theme name that + // holds the final override. + // @todo Try to prepare this in _system_rebuild_theme_data() already. + $theme->stylesheets_override = array(); // Grab stylesheets from base theme foreach ($base_theme as $base) { @@ -159,6 +163,12 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb } } } + if (!empty($base->info['stylesheets-override'])) { + $base_theme_path = dirname($base->filename); + foreach ($base->info['stylesheets-override'] as $basename) { + $theme->stylesheets_override[$basename] = $base_theme_path . '/' . $basename; + } + } } // Add stylesheets used by this theme. @@ -169,6 +179,11 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb } } } + if (!empty($theme->info['stylesheets-override'])) { + foreach ($theme->info['stylesheets-override'] as $basename) { + $theme->stylesheets_override[$basename] = $theme_path . '/' . $basename; + } + } // And now add the stylesheets properly foreach ($final_stylesheets as $media => $stylesheets) { diff --git a/core/modules/color/color.module b/core/modules/color/color.module index 56c04cf..680ceed 100644 --- a/core/modules/color/color.module +++ b/core/modules/color/color.module @@ -77,7 +77,7 @@ function _color_html_alter(&$vars) { if (drupal_basename($old_path) == drupal_basename($color_path)) { // Replace the path to the new css file. // This keeps the order of the stylesheets intact. - $vars['css'][$old_path]['data'] = $color_path; + $vars['css'][drupal_basename($old_path)]['data'] = $color_path; } } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php b/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php index 00e7f14..e7aa0e0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Ajax/FrameworkTest.php @@ -78,8 +78,11 @@ function testLazyLoad() { 'css' => drupal_get_path('module', 'system') . '/system.admin.css', 'js' => drupal_get_path('module', 'system') . '/system.js', ); + // CSS files are stored by basename, see drupal_add_css(). + $expected_css_basename = drupal_basename($expected['css']); + // @todo D8: Add a drupal_css_defaults() helper function. - $expected_css_html = drupal_get_css(array($expected['css'] => array( + $expected_css_html = drupal_get_css(array($expected_css_basename => array( 'type' => 'file', 'group' => CSS_DEFAULT, 'weight' => 0, @@ -135,7 +138,7 @@ function testLazyLoad() { // Verify the expected CSS file was added, both to Drupal.settings, and as // an Ajax command for inclusion into the HTML. - $this->assertEqual($new_css, $original_css + array($expected['css'] => 1), format_string('Page state now has the %css file.', array('%css' => $expected['css']))); + $this->assertEqual($new_css, $original_css + array($expected_css_basename => 1), format_string('Page state now has the %css file.', array('%css' => $expected['css']))); $this->assertCommand($commands, array('data' => $expected_css_html), format_string('Page now has the %css file.', array('%css' => $expected['css']))); // Verify the expected JS file was added, both to Drupal.settings, and as diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php index 9009bbb..8e89935 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php @@ -69,7 +69,7 @@ function testModuleInfo() { function testAddFile() { $path = drupal_get_path('module', 'simpletest') . '/simpletest.css'; $css = drupal_add_css($path); - $this->assertEqual($css[$path]['data'], $path, 'Adding a CSS file caches it properly.'); + $this->assertEqual($css['simpletest.css']['data'], $path); } /** diff --git a/core/modules/system/tests/themes/test_theme/test_theme.info b/core/modules/system/tests/themes/test_theme/test_theme.info index b5d1bfc..53a7624 100644 --- a/core/modules/system/tests/themes/test_theme/test_theme.info +++ b/core/modules/system/tests/themes/test_theme/test_theme.info @@ -3,16 +3,6 @@ description = Theme for testing the theme system core = 8.x hidden = TRUE -; Normally, themes may list CSS files like this, and if they exist in the theme -; folder, then they get added to the page. If they have the same file name as a -; module CSS file, then the theme's version overrides the module's version, so -; that the module's version is not added to the page. Additionally, a theme may -; have an entry like this one, without having the corresponding CSS file in the -; theme's folder, and in this case, it just stops the module's version from -; being loaded, and does not replace it with an alternate version. We have this -; here in order for a test to ensure that this correctly prevents the module -; version from being loaded, and that errors aren't caused by the lack of this -; file within the theme folder. -stylesheets[all][] = system.base.css +stylesheets-override[] = system.base.css settings[theme_test_setting] = default value diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php index 58bf751..a04ded8 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/CacheTest.php @@ -187,7 +187,7 @@ function testHeaderStorage() { $js_path = drupal_get_path('module', 'views_test_data') . '/views_cache.test.js'; $js = drupal_add_js(); - $this->assertTrue(isset($css[$css_path]), 'Make sure the css is added for cached views.'); + $this->assertTrue(isset($css[basename($css_path)]), 'Make sure the css is added for cached views.'); $this->assertTrue(isset($js[$js_path]), 'Make sure the js is added for cached views.'); $this->assertFalse(!empty($view->build_info['pre_render_called']), 'Make sure hook_views_pre_render is not called for the cached view.'); @@ -211,7 +211,7 @@ function testHeaderStorage() { $css = drupal_add_css(); $js = drupal_add_js(); - $this->assertFalse(isset($css[$system_css_path]), 'Make sure that unrelated css is not added.'); + $this->assertFalse(isset($css[basename($system_css_path)]), 'Make sure that unrelated css is not added.'); $this->assertFalse(isset($js[$system_js_path]), 'Make sure that unrelated js is not added.'); } diff --git a/core/themes/seven/seven.info b/core/themes/seven/seven.info index 87edba3..b737eaf 100644 --- a/core/themes/seven/seven.info +++ b/core/themes/seven/seven.info @@ -3,8 +3,14 @@ description = A simple one-column, tableless, fluid width administration theme. package = Core version = VERSION core = 8.x + stylesheets[screen][] = style.css +stylesheets-override[] = vertical-tabs.css +stylesheets-override[] = vertical-tabs-rtl.css +stylesheets-override[] = jquery.ui.theme.css + settings[shortcut_module_link] = 1 + regions[content] = Content regions[help] = Help regions[page_top] = Page top diff --git a/core/themes/seven/template.php b/core/themes/seven/template.php index b92d064..335f18e 100644 --- a/core/themes/seven/template.php +++ b/core/themes/seven/template.php @@ -104,20 +104,3 @@ function seven_tablesort_indicator($variables) { return theme('image', array('uri' => $theme_path . '/images/arrow-desc.png', 'alt' => t('sort descending'), 'width' => 13, 'height' => 13, 'title' => t('sort descending'))); } } - -/** - * Implements hook_css_alter(). - */ -function seven_css_alter(&$css) { - // Use Seven's vertical tabs style instead of the default one. - if (isset($css['core/misc/vertical-tabs.css'])) { - $css['core/misc/vertical-tabs.css']['data'] = drupal_get_path('theme', 'seven') . '/vertical-tabs.css'; - } - if (isset($css['core/misc/vertical-tabs-rtl.css'])) { - $css['core/misc/vertical-tabs-rtl.css']['data'] = drupal_get_path('theme', 'seven') . '/vertical-tabs-rtl.css'; - } - // Use Seven's jQuery UI theme style instead of the default one. - if (isset($css['core/misc/ui/themes/base/jquery.ui.theme.css'])) { - $css['core/misc/ui/themes/base/jquery.ui.theme.css']['data'] = drupal_get_path('theme', 'seven') . '/jquery.ui.theme.css'; - } -}