Skip to content

Instantly share code, notes, and snippets.

@jameswilson
Created August 9, 2014 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameswilson/33c1f5d405119a508ceb to your computer and use it in GitHub Desktop.
Save jameswilson/33c1f5d405119a508ceb to your computer and use it in GitHub Desktop.
Remove duplicate stylesheets for RTL themes that use _directional.scss
<?php
/**
* Implements hook_css_alter().
*/
function mytheme_css_alter(&$css) {
global $language;
// If the current language is RTL, find and remove CSS files from this
// theme that have the RTL overrides. Drupal's RTL methodology adds files
// that it finds containing the '-rtl' suffix, but doesnt remove the
// original LTR version. However, because _directional.scss generates
// two separate stylesheets with the same rules the original (LTR) version
// should be removed to avoid inflicting duplicate styles on RTL languages.
if ($language->direction == LANGUAGE_RTL) {
foreach ($css as $data => $item) {
// Remove original (LTR) version of all RTL stylesheets from this
// theme.
if ($item['type'] == 'file'
&& strpos($item['data'], 'mytheme')
&& strpos($item['data'], '-rtl.css')) {
$ltr = str_replace('-rtl.css', '.css', $item['data']);
unset($css[$ltr]);
}
}
}
}
@jameswilson
Copy link
Author

Why would you need this? See blog the post where this snippet further explained:

http://jwilson3.postach.io/right-to-left-theming-in-drupal-with-directional-scss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment