Created
August 9, 2014 12:18
-
-
Save jameswilson/33c1f5d405119a508ceb to your computer and use it in GitHub Desktop.
Remove duplicate stylesheets for RTL themes that use _directional.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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