If you configure a file type's file display settings to be anything other than "Image" (the one that comes built-in with the File Entity module) and are using the Media module to embed images in text, attributes such as width, height, etc., don't seem to appear on the image tag in the HTML.

This is related to #1834902: file_image formatter ignores dimensions overrides on files but that was for the case where you are using the built-in "Image" formatter.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David_Rothstein’s picture

Title: Displaying embedded media without using the File Entity module's built-in formatter does not shown attribute overrides » Displaying embedded media without using the File Entity module's built-in formatter ignores attribute overrides
Status: Active » Needs review
FileSize
905 bytes

Here is a patch.

It doesn't really look correct to me since conceptually I'm not sure the File Entity module should even be aware of the Media module's "overrides" concept. However, it's basically the same idea as what was committed in #1834902: file_image formatter ignores dimensions overrides on files.

This takes into account generic attributes in addition to width and height; perhaps the code that the above issue changed should do that too?

aaron’s picture

Status: Needs review » Needs work

I have tested this by changing the file display for images to the "large file icon" but it doesn't seem to work.

robertstaddon’s picture

@David_Rothstein, this patch was a lifesaver for me! Thank you.

After upgrading to the latest alpha versions of the File entity and Media modules, all of the attributes (including classes) were being stripped off rendered images that were embedded into my WYSIWYG editor using the Media module. The shortcodes in the WYSIWYG editor were correct, but when Drupal rendered the elements on the page, all of the attributes (including the critical classes to float the image to the left or right) were stripped off.

Interestingly enough, I discovered that this only occurred if any module that created a custom field formatter was enabled (e.g. I was using Colorbox, Flex Slider Fields, and Image URL Formatter). If I disabled those three modules, the attributes were mysteriously no longer stripped off.

After hours of troubleshooting, I finally tracked it down to the way File Entity is handling formatters. Your code above corrected the problem for me.

HairMachine’s picture

Thanks for this, also saved my bacon!

eigentor’s picture

We had the same Problem and I applied the patch to version alpha 2 of file entity.
Now we have a different problem on our drupal commerce site: #2104575: Alt and Title Tags keep vanishing

robertstaddon’s picture

I just upgraded to the alpha 3 of the File Entity and Media modules and this patch was still needed to allow Drupal to properly render element attributes. Thanks for providing this! It might be nice to go ahead and patch the File Entity module with this code.

rozh’s picture

Issue summary: View changes

Is it right to use $items[0]['override'][$property]? I've looked in $items and find $items[0]['metadata'][$property].

Changing that to 'metadata' helps me to add attributes to img tag. And it solves a problem with media_colorbox module #1909030: Colorbox very, very small when clickin on image.

dabblela’s picture

I've updated the patch in #1 to reflect that images store their height/width in a metadata property.

gmclelland’s picture

Status: Needs work » Needs review
Devin Carlson’s picture

I think that we want to allow anything in $file->override['attributes'] to override a property of the file.

The last submitted patch, 10: file-entity-image-dimensions-2058303-10-test-only.patch, failed testing.

Dave Reid’s picture

I tweaked this to read from $file->override since it made more sense to me than $items[0]['override'], and used array_merge() instead of the foreach loop.

Dave Reid’s picture

Status: Needs review » Fixed

Committed to 7.x-2.x.

  • Dave Reid committed a8952ab on 7.x-2.x
    Issue #2058303 by Devin Carlson, Dave Reid, manatwo, David_Rothstein:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.