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.
Problem/Motivation
When using the WYSIWYG editor to insert an image, if the view mode of the image is changed, classes added by the image style are not removed. This leads to classes like panopoly-image-quarter being associated with the image, regardless of the view mode selected.
Proposed resolution
Remove the classes as view modes are changed.
Remaining tasks
The difficult part - figuring out how to do it.
User interface changes
None
API changes
None (hopefully).
Data model changes
Original issue
The issue summary for #2422153: View mode classes accumulate when changing image view mode is valid for this issue as well, with this issue focusing on classes added by panopoly_images_preprocess_image_style().
Comment | File | Size | Author |
---|---|---|---|
#6 | panoply_2765007_6.patch | 2.92 KB | EternalLight |
Comments
Comment #2
dsnopekAnother question is why #2422163: Panopoly CSS causes issues with WYSIWYG image because of image style class names isn't working -- that issue was originally intended to solve this problem :-/
Comment #3
ultimike@dsnopek,
Admittedly, I don't have a full understanding of all the moving parts with this issue (Panopoly Image, Media, Media WYSIWYG, etc...), but in my testing/debugging, it appears that:
1. panopoly_images_preprocess_image_style() gets called when the "add media" WYSIWYG toolbar button is clicked and the various view modes are loaded in the Media modal window. It appears that it gets called once for each view mode listed in the "Display as" select box.
2. After a view mode is selected, and the modal "Submit" button is clicked - the panopoly_images_preprocess_image_style() is not called.
So, if an existing node (one with an image added via the "add media" button previously) is edited...
1. When initially loaded in the WYSIWYG editor, if the image's previous view mode is Quarter Right, then the media tag will contain
"class":"panopoly-image-quarter media-element file-quarter-right"}
.2. If the image is selected, then the "add media" button is clicked (to change the "Display as" setting) and the "Display as" select is set to "Original size". Once submitted, the media tag then contains:
"class":"panopoly-image-quarter media-element file-default"
.At this point, I don't understand how the classes from the image style are supposed to be communicated to the media widget (specifically, its JavaScript code which is clearly handling the updating of the media tag).
-mike
Comment #4
ultimikeAs an initial step, I decided to try to reproduce the issue on a fresh install of Panopoly (7.x-1.37). Here's what I did:
So, it appears that the issue isn't with the display of the node, rather the issue is with the display of the node while displayed in the WYSIWYG editor.
-mike
Comment #5
dsnopekOk, so it sounds like #2422163: Panopoly CSS causes issues with WYSIWYG image because of image style class names fixed display of the content (in PHP), but not the situation in the WYSIWYG (in Javascript) :-/
Fixing this would probably involve patching (or monkey patching) the Javascript in Media. Or maybe a hook-like thing could be added to the Media Javascript, that would allow Panopoly to subscribe to an event or set a function somewhere that would filter the classes used?
Looking at the patch on #2422153-10: View mode classes accumulate when changing image view mode, that could be the place that the hook (or inline filtering) would need to happen, although, I didn't test that patch.
A hook-like thing would probably be ideal, because that's something that could get actually merged into Media. After that, if we can monkey patch the Javascript, that would be better than an actual patch (because a Panopoly-specific patch would never get committed upstream).
I hope that helps!
Comment #6
EternalLight CreditAttribution: EternalLight as a volunteer commentedHello,
I took a look at this issue and figured that old (initial) panoply CSS class remains in editor after editing an image because it is not updated in media_wysiwyg.filter.js. The attached patch fixes this issue. Note that it could be applied on Media 2.0 that comes with Panoply installation profile out of the box and might not work with the current stable media release (2.3 at the moment of writing).
Please test it out and let me know if it helped.
Comment #7
cboyden CreditAttribution: cboyden commented