Posted by willvincent on October 13, 2011 at 7:51pm
7 followers
| Project: | Wysiwyg |
| Version: | 7.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
It would be nice to be able to select which theme's css to apply when you opt to use the 'use css' setting for wysiwyg profile configuration.
The default behavior is to use the current theme, which is fine, unless you're using the admin theme for content editing. In that instance the current theme is the admin theme so content in the editor doesn't properly reflect how it will look on the front end.
Comments
#1
Here's a patch that seems to work.. needs review.
I've supplied a git patch, and an older p0 format that will apply with older versions of drush make.
#2
Oops.. the previous patch doesn't handle stylesheets from a base theme if the selected theme is a sub theme.
These will handle that, but only a subtheme from a single base theme, not a sub theme of another sub theme.. that part would need more work.
#3
Thanks for the patch! Always nice to see feature requests with actual code! :)
There are already some ongoing discussions regarding themes and I'd like to get your opinion on those. In essence, pros/cons vs your approach, a kind of self-review since I don't have time to do it myself yet. Hope you don't mind. ;)
An alternate approach is discussed in #1017564: Allow user to dynamically change in-editor theme (no patch yet but a nice mockup).
#835682: %t (path_to_theme() ) returns modules/field (or whatever module is creating the wysiwyg) instead of the active theme. is most likely relevant to this discussion as well.
#4
No problem! As a module maintainer myself I always appreciate when people actually provide patches as well, so I generally try to return the favor whenever possible. :)
I looked at and commented on #1017564: Allow user to dynamically change in-editor theme
I'll try to read through #835682: %t (path_to_theme() ) returns modules/field (or whatever module is creating the wysiwyg) instead of the active theme. tomorrow.
#5
The discussion in #835682: %t (path_to_theme() ) returns modules/field (or whatever module is creating the wysiwyg) instead of the active theme. is very useful, however it's really unrelated to this issue as it deals with the path to the theme when "Editor CSS" is set to "Define CSS", i.e. manually entering entering the path to specific stylesheet files.
The ideas in #1017564: Allow user to dynamically change in-editor theme are great, but require quite a bit of work to be fully functional.
I think the patch by willvincent here in #2 is the correct approach to allow setting which theme's css styles are loaded into the editor.
I've updated the patch:
The method here loads any base_theme css (I've changed the key from 'base theme' to 'base_theme'), and then any theme css, but only if they're not for print. This also removes the assumption that stylesheets['all'] is always populated (e.g. seven places its css in stylesheets['screen'] leaving stylesheets['all'] empty). As mentioned, this loading doesn't account for sub themes of another sub theme.
#6
Thanks for the patches, arguments and detailed analysis!
@fenstrat, yes, #835682: %t (path_to_theme() ) returns modules/field (or whatever module is creating the wysiwyg) instead of the active theme. does not seem to affect this issue directly.
Wow, getting the correct stylesheets is getting complicated, but I guess that is to be expected considering how complex themes can be.
A couple of questions came into mind while reading the patch (haven't tested it yet).
file_exists()check inwysiwyg_get_css()? If we skip it we only risk requesting a stylesheet that doesn't exist. By skipping request for files Wysiwyg knows doesn't exist, we're hiding that fact from the admins/developers. (No entries in the 404 logs, no markup to indicate the files should exist.) It looks likedrupal_get_css()anddrupal_add_css()don't usefile_exists(), so why should we?Patch notes:
+++ b/wysiwyg.moduleundefined@@ -602,28 +602,46 @@ function wysiwyg_get_editor_config($profile, $theme) {
*/
-function wysiwyg_get_css() {
+function wysiwyg_get_css($theme) {
Could we default to using the current theme from some global to perhaps avoid the update hook and/or not break backwards compatibility (in the odd case someone other than Wysiwyg actually uses the function)?
#7
@TwoD, no worries, thanks for the feedback, sorry this fell off my radar for a while.
Addressing #6
Drupal.wysiwygAttachbut am unsure where a message could be added.file_exists()check inwysiwyg_get_css()is gone.$themeparam towysiwyg_get_css($theme = '')which will ensure backwards compatibility.#8
This patch is not completely compatible with Omega subthemes -- if I select my Omega subtheme, its grid CSS does not get loaded in the WYSIWYG iframe. Probably due to the trickery involved in how Alpha/Omega manage CSS. I have no idea what the fix would be, unfortunately, but I figure I should reset to needs work.... :/
#9
I would suggest allowing this to be set to "admin theme", "default theme", "node admin theme" and "other theme". That way if I were to export all the WYSIWYG settings I would probably have it set to "default theme" and could reuse the same settings on a new website. Sorry if this has already been brought up, I have just skimmed through the discussions and latest patch.