Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
mothership is all about removing... but I have to say I do not like clicking around to remove my CSS.
With hook_css_alter we can remove CSS and with some magic with can use directly an css-exclude key in .info.
somthing like
css-excclude[] = modules/system/system.css
What will be very cool is if we can use * in path and even in name (so you can remove in one line all the somthings.theme.css.
css-excclude[] = */system.css
css-excclude[] = *.theme.css
The theme twitter_bootstrap (and others) already implement something similar.
function twitter_bootstrap_css_alter(&$css) {
//global $theme_key;
//$theme_path = drupal_get_path('theme', $theme_key);
$excludes = _twitter_bootstrap_alter(twitter_bootstrap_theme_get_info('exclude'), 'css');
$css = array_diff_key($css, $excludes);
}
function twitter_bootstrap_js_alter(&$js) {
$excludes = _twitter_bootstrap_alter(twitter_bootstrap_theme_get_info('exclude'), 'js');
$js = array_diff_key($js, $excludes);
}
function _twitter_bootstrap_alter($files, $type) {
$output = array();
foreach($files as $key => $value) {
if(isset($files[$key][$type])) {
foreach($files[$key][$type] as $file => $name) {
$output[$name] = FALSE;
}
}
}
return $output;
}
Comments
Comment #1
betovargDont know about JS but, isnt that why FOAD is in the .info file?
Comment #2
gagarine CreditAttribution: gagarine commentedFOAD??
Comment #3
betovargYeah, its a known technique:
http://drupal.org/node/1536790
Comment #4
gagarine CreditAttribution: gagarine commentedah ok.. I know about this.. didn't know we made a cool name for this not intuitive and terrible design.
This use a file_exist to check than your files doesn't exist! And for the themer side, by looking at the .info he can't know if you add, remove or overwrite a CSS...
It also doesn't support wildcard.
Comment #5
realityloopIf you use the magic module you can add excludes for CSS and JS in the info file, in fact 3.x has some default magic settings in place already