By sarasioux on
I'm working on converting a module from Drupal5 to Drupal6. In my D5 version, I had a menu_hook creating a file called "mymodule.css", which I then added via drupal_add_css.
However, it seems that since vD6, the add_css functionality now checks for file_exists before allowing anything to be added. Whyyyyyyyyyy? Not all CSS files are going to physically exist.
If anyone knows a good workaround to elegantly include dynamic menu_hook CSS via a module without having to mess with the theme, please let me know.
Thanks!
Comments
What are you trying to
What are you trying to do?
You're trying to add css in hook_menu, which just defines new menu items? Why would menu_hook create (generate?) css files? Are you trying to modify the output of all menu items, only the ones your module is creating, or what? Are you trying to add a css file off of a menu callback?
I sounds to me that he is
I sounds to me that he is creating a menu callback for a path (/path/file.css), where the output of that menu callback is a .css file. There is nothing wrong in doing that at all.
I would have thought that using the valid path in drupal_add_css would work fine as the file does theoretically exist. If not then it is likely a bug and you should file an issue in the appropriate place.
You can do it in the preprocess function
Check this out, Adding styles through the API.
It's evident that the issue
It's evident that the issue here is that both drupal_add_css and drupal_get_css have now implemented file_exists() calls, and as the css file is actually a dynamically created Drupal path it is returning false. This seems to be a huge over site in core.
Edit: Have posted an issue - #329812: Cannot add hook_menu-defined CSS with drupal_add_css()
Thank You!
Thanks Deciphered for understanding the issue, posting the bug report, and writing the patch that quickly. :) You just made me love open source communities a little bit more.
- Sara
You're welcome
Hi Sara,
I can take the credit for the two first parts, and you're more than welcome :), but I didn't write the patch, that credit belongs with Dave Reid.
Cheers,
Deciphered.