Issue identified in #2067063: Wysiwyg integration is broken. See comments #68, #101, #132, and #134.

In a nutshell: image_style_transform_dimensions() will set the height and width attributes according to the image style settings, effectively overwriting any height and width attribute modifications made via the wysiwyg. I have been unable to identify any hooks or theme overrides where we might be able to cleanly re-overwrite these attributes.

The proposed solution is to ensure that height and width attribute overrides are always reflected in a style attribute, which will take precedent when rendering the image, thus ensuring that the image is rendered with the height and width as set by the user.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

John Pitcairn’s picture

Other implementations will want to override the dimensions in php or css, regardless of what the person editing the content in wysiwyg thinks looks OK in their wysiwyg edit form at whatever width they happen to be using that day.

If there are height and width rules added by js in an inline style attribute after the page loads, and something else expects to override those, the only way to do so is by adding an !important declaration in a stylesheet, or running more js. Everything has to escalate.

Maybe the overriding implementation wants to calculate a new width/height based on the requested width compared to something else, like the node view mode, or whatever. Maybe it needs to be pixels, or a percentage, or ems.

A js-only approach seems just as hacky as a server-side preg_replace of attributes to me. If we want an alter() hook or theme function to allow this, where might that live? It's almost certainly a better approach than post-processing in js, IMO.

ParisLiakos’s picture

I was looking exactly at this this afternoon..and i couldnt think of an elegant way to override image_style_transform_dimensions()..maybe thats the only way, setting the style attribute in either php or js..maybe js is the right place to do it

+++ b/js/media.filter.js
@@ -174,6 +174,20 @@
+            if (!!element.attr(a)) {
...
+            else if (!!element[a]()) {

i just dont understand why we do this instead of just
if (element.attr(a))

wouldnt the end result be the same and less confusing?

ParisLiakos’s picture

re #1 : if you consider that this is the behavior of ckeditor when resizing images, this approach cant be that bad.

i dont like it too, but well i cant think another way

John Pitcairn’s picture

I don't think ckeditor's behavior is any good either. The user-requested width and height are static attributes and are accessible on the server side, we have valid (in xhtml or html5) width and height attributes, and client-side js is not an appropriate place to be outputting those (and is difficult to override).

Personally I think it would be better for media module to override the width and height attribute in php via preg_replace(), if no better solution exists, and push for an appropriate override in image module. That way, the way is left clear for other modules to at least add a simple stylesheet without !important rules.

I will take a closer look at this too.

John Pitcairn’s picture

I see. So without the patch, if the user does not override the default width and height, an inline style with default width and height is applied anyway, even though the width and height attributes are correct. This patch overrides that default inline style. I'm fine with that, my complaint is that there is an inline style in the first place.

I can still manipulate or remove the inline style and attributes prior to rendering. No further objections from me here.

David_Rothstein’s picture

Here's a version that works with #2126755: Improve Media's WYSIWYG Macro handling applied. I gave it the "do-not-test" suffix since the patch won't apply otherwise.

David_Rothstein’s picture

Component: Code » Media WYSIWYG

Fixing component.

asrob’s picture

Status: Needs review » Reviewed & tested by the community

Hi,

it works well on my local development environment. I attached two images and they have different sizes in ckeditor and after submitted node they're looking good.

joseph.olstad’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Assigned: kaidjohnson » joseph.olstad
FileSize
1.16 KB

Rerolled, patch still applied, but with offset, just rerolling it and run it against the testbot.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

probably needs a re-review, due to the new functionality in the latest versions of media

Chris Matthews’s picture

Assigned: joseph.olstad » Unassigned