2006/10/31, Khalid B <kb@2bits.com>:
Hello all.
Many modules have their own mymodule.css or mymodule.js
Most of these are added via:
theme_add_style(drupal_get_path('module', 'mymodule')).'/mymodule.css');
This is often called in hook_menu() so as to get in as early as possible.
Themes almost always need to override those css files. The way it is done is to go to the mymodule directory and edit mymodule.css.
The problem here is when one upgrades, they have to be very careful not to overwrite the changes. What is worse, if one is upgrading from cvs directly, then there could be conflicts resulting in invalid data in the file.
I think this is not an issue. If you want to override module's css rules, just do it in your theme's style.css. This is added lastly, so you are able to override its css rules using the same css selector or one with a high priority. You can also use the !important flag if you are having problems with cascading order.
So, in order to make this easier for all, it is best if this is written as: theme('add_style', drupal_get_path('module', 'mymodule')).'/mymodule.css');
This way, the theme can say:
function mytheme_add_style($path) { $file = basename($path); theme_add_style(base_path() . path_to_theme() . '/' . $file); }
This way, the css file for each module has a copy in the theme directory that can be customized, and and the rest of the stuff does not get touched.
Some modules do this already, most do not.
Here is the status in 4.7 today:
$ grep "theme.*(.*add_style" */* | awk -F: '{print $1}' | sort -u | wc -l 19
$ grep "theme_add_style" */* | awk -F: '{print $1}' | sort -u | wc -l 77
So, module owners should be encouraged to use:
theme('add_style', ...)
instead of
theme_add_style( ...)
Is it enough that I post here, or is there some other mechanism (short of opening 77 issues for 77 modules ...)
The theme_add_style() function have been replaced with drupal_add_css() in Drupal 5. Henrique