From 74a431e79a31d3d2dbec8ac65f28edb432765f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Fri, 5 Oct 2007 14:50:25 +0000 Subject: [PATCH] #163785 by Eaton, dvessel and quicksketch: theme .info files should be able to override core and module CSS files based on file basenames --- includes/bootstrap.inc | 1 + includes/common.inc | 38 +++++++++++++++++++++ modules/system/system-menus-rtl.css | 18 ++++++++++ modules/system/system-menus.css | 50 +++++++++++++++++++++++++++ modules/system/system-rtl.css | 17 +--------- modules/system/system.css | 52 ----------------------------- modules/system/system.module | 1 + 7 files changed, 109 insertions(+), 68 deletions(-) create mode 100644 modules/system/system-menus-rtl.css create mode 100644 modules/system/system-menus.css diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 36d9df5da68..c0527767ad3 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -987,6 +987,7 @@ function drupal_maintenance_theme() { unicode_check(); drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module'); drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module'); + drupal_add_css(drupal_get_path('module', 'system') .'/system-menus.css', 'module'); $theme = ''; // Special case registry of theme functions used by the installer diff --git a/includes/common.inc b/includes/common.inc index 1d53d873653..650aa90dc02 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1495,10 +1495,20 @@ function drupal_add_link($attributes) { /** * Adds a CSS file to the stylesheet queue. * + * Themes may replace module-defined CSS files by adding a stylesheet with the + * same filename. For example, themes/garland/system-menus.css would replace + * modules/system/system-menus.css. This allows themes to override complete + * CSS files, rather than specific selectors, when necessary. + * * @param $path * (optional) The path to the CSS file relative to the base_path(), e.g., * /modules/devel/devel.css. * + * Modules should always prefix the names of their CSS files with the module + * name, for example: system-menus.css rather than simply menus.css. Themes + * can override module-supplied CSS files based on their filenames, and this + * prefixing helps prevent confusing name collisions for theme developers. + * * If the direction of the current language is right-to-left (Hebrew, * Arabic, etc.), the function will also look for an RTL CSS file and append * it to the list. The name of this file should have an '-rtl.css' suffix. @@ -1506,6 +1516,10 @@ function drupal_add_link($attributes) { * file added to the list, if exists in the same directory. This CSS file * should contain overrides for properties which should be reversed or * otherwise different in a right-to-left display. + * + * If the original CSS file is being overridden by a theme, the theme is + * responsible for supplying an accompanying RTL CSS file to replace the + * module's. * @param $type * (optional) The type of stylesheet that is being added. Types are: module * or theme. @@ -1548,6 +1562,30 @@ function drupal_add_css($path = NULL, $type = 'module', $media = 'all', $preproc if (!isset($css[$media])) { $css[$media] = array('module' => array(), 'theme' => array()); } + + // If a theme is adding the current stylesheet, check for any existing CSS files + // with the same name. If they exist, remove them and allow the theme's own CSS + // file to replace it. + if ($type == 'theme') { + foreach ($css[$media]['module'] as $old_path => $old_preprocess) { + // Match by style sheet name. + if (basename($path) == basename($old_path)) { + unset($css[$media]['module'][$old_path]); + + // If the current language is RTL and the CSS file had an RTL variant, + // pull out the original. The theme must provide it's own RTL style. + if (defined('LANGUAGE_RTL') && $language->direction == LANGUAGE_RTL) { + $rtl_old_path = str_replace('.css', '-rtl.css', $old_path); + if (isset($css[$media]['module'][$rtl_old_path])) { + unset($css[$media]['module'][$rtl_old_path]); + } + } + // Set the preprocess state of the current module, then exit the search loop. + $preprocess = $old_preprocess; + break; + } + } + } $css[$media][$type][$path] = $preprocess; // If the current language is RTL, add the CSS file with RTL overrides. diff --git a/modules/system/system-menus-rtl.css b/modules/system/system-menus-rtl.css new file mode 100644 index 00000000000..4ef54c390d8 --- /dev/null +++ b/modules/system/system-menus-rtl.css @@ -0,0 +1,18 @@ +/* $Id$ */ + +ul.menu { + text-align:right; +} +ul.menu li { + margin: 0 0.5em 0 0; +} +li.expanded { + padding: 0.2em 0 0 0.5em; +} +li.collapsed { + list-style-image: url(../../misc/menu-collapsed-rtl.png); + padding: 0.2em 0 0 0.5em; +} +li.leaf { + padding: 0.2em 0 0 0.5em; +} diff --git a/modules/system/system-menus.css b/modules/system/system-menus.css new file mode 100644 index 00000000000..369dcc4e7d5 --- /dev/null +++ b/modules/system/system-menus.css @@ -0,0 +1,50 @@ +/* $Id$ */ + +ul.menu { + list-style: none; + border: none; + text-align:left; /* LTR */ +} +ul.menu li { + margin: 0 0 0 0.5em; /* LTR */ +} +li.expanded { + list-style-type: circle; + list-style-image: url(../../misc/menu-expanded.png); + padding: 0.2em 0.5em 0 0; /* LTR */ + margin: 0; +} +li.collapsed { + list-style-type: disc; + list-style-image: url(../../misc/menu-collapsed.png); /* LTR */ + padding: 0.2em 0.5em 0 0; /* LTR */ + margin: 0; +} +li.leaf { + list-style-type: square; + list-style-image: url(../../misc/menu-leaf.png); + padding: 0.2em 0.5em 0 0; /* LTR */ + margin: 0; +} +li a.active { + color: #000; +} +td.menu-disabled { + background: #ccc; +} +ul.links { + margin: 0; + padding: 0; +} +ul.links.inline { + display: inline; +} +ul.links li { + display: inline; + list-style-type: none; + padding: 0 0.5em; +} +.block ul { + margin: 0; + padding: 0 0 0.25em 1em; /* LTR */ +} diff --git a/modules/system/system-rtl.css b/modules/system/system-rtl.css index bb5689e0e68..cbd7df44f1f 100644 --- a/modules/system/system-rtl.css +++ b/modules/system/system-rtl.css @@ -21,22 +21,7 @@ dl.multiselect dt, dl.multiselect dd { float: right; margin: 0 0 0 1em; } -ul.menu { - text-align:right; -} -ul.menu li { - margin: 0 0.5em 0 0; -} -li.expanded { - padding: 0.2em 0 0 0.5em; -} -li.collapsed { - list-style-image: url(../../misc/menu-collapsed-rtl.png); - padding: 0.2em 0 0 0.5em; -} -li.leaf { - padding: 0.2em 0 0 0.5em; -} + .block ul { padding: 0 1em 0.25em 0; } diff --git a/modules/system/system.css b/modules/system/system.css index 6cb91f001a5..ed90a3562f8 100644 --- a/modules/system/system.css +++ b/modules/system/system.css @@ -181,58 +181,6 @@ dl.multiselect .form-item { display: inline; } -/* -** Menus -*/ -ul.menu { - list-style: none; - border: none; - text-align:left; /* LTR */ -} -ul.menu li { - margin: 0 0 0 0.5em; /* LTR */ -} -li.expanded { - list-style-type: circle; - list-style-image: url(../../misc/menu-expanded.png); - padding: 0.2em 0.5em 0 0; /* LTR */ - margin: 0; -} -li.collapsed { - list-style-type: disc; - list-style-image: url(../../misc/menu-collapsed.png); /* LTR */ - padding: 0.2em 0.5em 0 0; /* LTR */ - margin: 0; -} -li.leaf { - list-style-type: square; - list-style-image: url(../../misc/menu-leaf.png); - padding: 0.2em 0.5em 0 0; /* LTR */ - margin: 0; -} -li a.active { - color: #000; -} -td.menu-disabled { - background: #ccc; -} -ul.links { - margin: 0; - padding: 0; -} -ul.links.inline { - display: inline; -} -ul.links li { - display: inline; - list-style-type: none; - padding: 0 0.5em; -} -.block ul { - margin: 0; - padding: 0 0 0.25em 1em; /* LTR */ -} - /* ** Tab navigation */ diff --git a/modules/system/system.module b/modules/system/system.module index f184b8f913a..115db85481a 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -451,6 +451,7 @@ function system_init() { // Add the CSS for this module. drupal_add_css(drupal_get_path('module', 'system') .'/defaults.css', 'module'); drupal_add_css(drupal_get_path('module', 'system') .'/system.css', 'module'); + drupal_add_css(drupal_get_path('module', 'system') .'/system-menus.css', 'module'); } /**