On a site I maintain they have their Image file_entity bundle set up with a Link field. When an image with a filled-in Link field is added to a node's body field using the WYSIWYG module integration, the embedded file entity code ends up with invalid JSON, so media_wysiwyg_token_to_markup() is unable to extract the file information to display it.

The embedded media code looks like this:

[[{"fid":"123","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":"","field_caption[und][0][value]":"","field_link[und][0][url]":"<a href="http://example.com/">http://example.com/</a>","field_iptc_object_name[und][0][tid]":"","field_iptc_object_name[und][0][value]":"","field_iptc_object_name[und][0][timezone]":"","field_iptc_object_name[und][0][value2]":"","field_exif_imagedescription[und][0][tid]":"","field_exif_imagedescription[und][0][value]":"","field_exif_imagedescription[und][0][timezone]":"","field_exif_imagedescription[und][0][value2]":"","field_iptc_keywords[und][0][tid]":"","field_iptc_keywords[und][0][value]":"","field_iptc_keywords[und][0][timezone]":"","field_iptc_keywords[und][0][value2]":"","field_iptc_keywords[und][0][_weight]":"0","field_gallery_id[und][0][value]":""},"type":"media","attributes":{"height":732,"width":500,"class":"media-element file-default"},"link_text":null}]]

Both the Default and WYSIWYG view modes for the Image file entity bundle have the "Link" field set to "Hidden".

Checking the database, the file_link_url value just contains "http://example.com/".

As you can see, the field_link's "url" value is converted to a link when it is added to the WYSIWYG. The value is first converted to a link and then the string is not encoded properly in the jSON, most likely the quotes around the URL in the link.

CommentFileSizeAuthor
#6 media-n2762817-6.patch1.01 KBdamienmckenna

Comments

DamienMcKenna created an issue. See original summary.

damienmckenna’s picture

Issue summary: View changes
damienmckenna’s picture

Issue summary: View changes
damienmckenna’s picture

Digging through it more, the value stored in the node's body field is actually the following:

[[{"fid":"9357","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":"","field_caption[und][0][value]":"","field_link[und][0][url]":"http://example.com/","field_iptc_object_name[und][0][tid]":"","field_iptc_object_name[und][0][value]":"","field_iptc_object_name[und][0][timezone]":"","field_iptc_object_name[und][0][value2]":"","field_exif_imagedescription[und][0][tid]":"","field_exif_imagedescription[und][0][value]":"","field_exif_imagedescription[und][0][timezone]":"","field_exif_imagedescription[und][0][value2]":"","field_iptc_keywords[und][0][tid]":"","field_iptc_keywords[und][0][value]":"","field_iptc_keywords[und][0][timezone]":"","field_iptc_keywords[und][0][value2]":"","field_iptc_keywords[und][0][_weight]":"0","field_iptc_keywords[und][1][tid]":"","field_iptc_keywords[und][1][value]":"","field_iptc_keywords[und][1][timezone]":"","field_iptc_keywords[und][1][value2]":"","field_iptc_keywords[und][1][_weight]":"1","field_gallery_id[und][0][value]":""},"type":"media","attributes":{"height":732,"width":500,"class":"media-element file-default"},"link_text":null}]]

This means that the value is being changed prior to getting to text_field_load().

damienmckenna’s picture

Title: Incorrect JSON encoding of file entity fields in WYSIWYG breaks file rendering » Running "Convert URLs" filter before Media filter can break embedded media
Component: Code » Media WYSIWYG
Category: Bug report » Task

Ok, so the problem turned out to be that the "Convert URLs into links" filter was running before the Media filter and was breaking the JSON.

damienmckenna’s picture

StatusFileSize
new1.01 KB

This updates the help message on the Media filter recommending it be ran before the "Convert URLs" filter.

damienmckenna’s picture

Status: Active » Needs review
nebel54’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
Status: Needs review » Reviewed & tested by the community

That hint is a great idea (took me some time to find the problem today), patch still works for both (3.x and 2.x).

  • DamienMcKenna authored 7153e0d on 7.x-3.x
    Issue #2762817 by DamienMcKenna: Running "Convert URLs" filter before...

  • DamienMcKenna authored a6c9aa3 on 7.x-2.x
    Issue #2762817 by DamienMcKenna: Running "Convert URLs" filter before...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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