summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/locale/locale.module27
-rw-r--r--modules/simpletest/tests/common.test74
-rw-r--r--modules/system/system.api.php13
-rw-r--r--modules/system/system.module8
4 files changed, 115 insertions, 7 deletions
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 0ece6958b..3e6c987fb 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -583,6 +583,33 @@ function locale_js_alter(&$javascript) {
}
}
+/*
+ * Implement hook_css_alter().
+ *
+ * This function checks all CSS files currently added via drupal_add_css() and
+ * and checks to see if a related right to left CSS file should be included.
+ */
+function locale_css_alter(&$css) {
+ global $language;
+
+ // If the current language is RTL, add the CSS file with the RTL overrides.
+ if ($language->direction == LANGUAGE_RTL) {
+ foreach ($css as $data => $item) {
+ // Only provide RTL overrides for files.
+ if ($item['type'] == 'file') {
+ $rtl_path = str_replace('.css', '-rtl.css', $item['data']);
+ if (file_exists($rtl_path) && !isset($css[$rtl_path])) {
+ // Replicate the same item, but with the RTL path and a little larger
+ // weight so that it appears directly after the original CSS file.
+ $item['data'] = $rtl_path;
+ $item['weight'] += 0.01;
+ $css[$rtl_path] = $item;
+ }
+ }
+ }
+ }
+}
+
// ---------------------------------------------------------------------------------
// Language switcher block
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index c396e9120..60265bd8d 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -203,7 +203,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
}
function setUp() {
- parent::setUp('php');
+ parent::setUp('php', 'locale');
// Reset drupal_add_css() before each test.
drupal_static_reset('drupal_add_css');
}
@@ -221,7 +221,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
function testAddFile() {
$path = drupal_get_path('module', 'simpletest') . '/simpletest.css';
$css = drupal_add_css($path);
- $this->assertEqual($css['all']['module'][$path], TRUE, t('Adding a CSS file caches it properly.'));
+ $this->assertEqual($css[$path]['data'], $path, t('Adding a CSS file caches it properly.'));
}
/**
@@ -249,7 +249,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
$css_preprocessed = '<style type="text/css">' . drupal_load_stylesheet_content($css, TRUE) . '</style>';
drupal_add_css($css, 'inline');
$css = drupal_get_css();
- $this->assertEqual($css, $css_preprocessed, t('Rendering preprocessed inline CSS adds it to the page.'));
+ $this->assertEqual($css, "\n" . $css_preprocessed, t('Rendering preprocessed inline CSS adds it to the page.'));
}
/**
@@ -280,6 +280,74 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
$this->drupalGet('node/' . $node->nid);
$this->assertRaw($expected, t('Inline stylesheets appear in the full page rendering.'));
}
+
+ /**
+ * Test CSS ordering.
+ */
+ function testRenderOrder() {
+ // A module CSS file.
+ drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');
+ // A few system CSS files, ordered in a strange way.
+ $system_path = drupal_get_path('module', 'system');
+ drupal_add_css($system_path . '/defaults.css', array('weight' => CSS_SYSTEM));
+ drupal_add_css($system_path . '/system.css', array('weight' => CSS_SYSTEM - 10));
+ drupal_add_css($system_path . '/system-menus.css', array('weight' => CSS_SYSTEM));
+
+ $expected = array(
+ $system_path . '/system.css',
+ $system_path . '/defaults.css',
+ $system_path . '/system-menus.css',
+ drupal_get_path('module', 'simpletest') . '/simpletest.css',
+ );
+
+ $css = drupal_get_css();
+ if (preg_match_all('/href="' . preg_quote(base_path(), '/') . '([^?]+)\?/', $css, $matches)) {
+ $result = $matches[1];
+ }
+ else {
+ $result = array();
+ }
+
+ $this->assertIdentical($result, $expected, t('The CSS files are in the expected order.'));
+ }
+
+ /**
+ * Test CSS override.
+ */
+ function testRenderOverride() {
+ drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
+ drupal_add_css(drupal_get_path('module', 'simpletest') . '/tests/system.css');
+
+ // The dummy stylesheet should be the only one included.
+ $css = drupal_get_css();
+ $this->assert(strpos($css, drupal_get_path('module', 'simpletest') . '/tests/system.css') !== FALSE, t('The overriding CSS file is output.'));
+ $this->assert(strpos($css, drupal_get_path('module', 'system') . '/system.css') === FALSE, t('The overriden CSS file is not output.'));
+
+ drupal_add_css(drupal_get_path('module', 'simpletest') . '/tests/system.css');
+ drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
+
+ // The standard stylesheet should be the only one included.
+ $css = drupal_get_css();
+ $this->assert(strpos($css, drupal_get_path('module', 'system') . '/system.css') !== FALSE, t('The overriding CSS file is output.'));
+ $this->assert(strpos($css, drupal_get_path('module', 'simpletest') . '/tests/system.css') === FALSE, t('The overriden CSS file is not output.'));
+ }
+
+ /**
+ * Tests Locale module's CSS Alter to include RTL overrides.
+ */
+ function testAlter() {
+ // Switch the language to a right to left language and add system.css.
+ global $language;
+ $language->direction = LANGUAGE_RTL;
+ drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
+
+ // Check to see if system-rtl.css was also added.
+ $css = drupal_get_css();
+ $this->assert(strpos($css, drupal_get_path('module', 'system') . '/system-rtl.css') !== FALSE, t('CSS is alterable as right to left overrides are added.'));
+
+ // Change the language back to left to right.
+ $language->direction = LANGUAGE_LTR;
+ }
}
/**
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 2a3fbec7b..685f16ac3 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -281,6 +281,19 @@ function hook_library_alter(&$libraries, $module) {
}
/**
+ * Alter CSS files before they are output on the page.
+ *
+ * @param $css
+ * An array of all CSS items (files and inline CSS) being requested on the page.
+ * @see drupal_add_css()
+ * @see drupal_get_css()
+ */
+function hook_css_alter(&$css) {
+ // Remove defaults.css file.
+ unset($css[drupal_get_path('module', 'system') . '/defaults.css']);
+}
+
+/**
* Perform alterations before a page is rendered.
*
* Use this hook when you want to add, remove, or alter elements at the page
diff --git a/modules/system/system.module b/modules/system/system.module
index 77e93f3f5..1fb124faa 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -1327,13 +1327,13 @@ function system_init() {
if (arg(0) == 'admin' || (variable_get('node_admin_theme', '0') && arg(0) == 'node' && (arg(1) == 'add' || arg(2) == 'edit'))) {
global $custom_theme;
$custom_theme = variable_get('admin_theme', 0);
- drupal_add_css(drupal_get_path('module', 'system') . '/admin.css');
+ drupal_add_css(drupal_get_path('module', 'system') . '/admin.css', array('weight' => CSS_SYSTEM));
}
// Add the CSS for this module.
- drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css');
- drupal_add_css(drupal_get_path('module', 'system') . '/system.css');
- drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css');
+ drupal_add_css(drupal_get_path('module', 'system') . '/defaults.css', array('weight' => CSS_SYSTEM));
+ drupal_add_css(drupal_get_path('module', 'system') . '/system.css', array('weight' => CSS_SYSTEM));
+ drupal_add_css(drupal_get_path('module', 'system') . '/system-menus.css', array('weight' => CSS_SYSTEM));
// Ignore slave database servers for this request.