Invalid argument supplied for foreach() in taxonomy_field_widget_form() when embedding a file entity that has a a term reference field.

Steps to reproduce
In the WYSIWYG, embed a file with terms associated with it.
File with tags

Edit the File
File with tags stripped

Or if you just embed a file without any tags, the error appears.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bneil’s picture

jvandyk’s picture

This is happening because when media.format_form.js line 48 sets the initial value for the Tag field, it doesn't understand that the Tag field is actually a multiple value field, not just a regular text field. Therefore, if there is no value in the field, it says, duh, I'll set this to an empty string value in the string that is generated for the filter, instead of an empty array.

<p>[[{"fid":"5","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":"","media_description[und][0][value]":"","field_tags[und]":""},"type":"media","attributes":{"class":"file media-element file-default"},"link_text":"foo.jpg"}]]</p>

Should be:

<p>[[{"fid":"5","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":"","media_description[und][0][value]":"","field_tags[und]":{}},"type":"media","attributes":{"class":"file media-element file-default"},"link_text":"foo.jpg"}]]</p>

This error cascades all the way down through many layers until Taxonomy ultimately complains about it.

mirzu’s picture

Dave Reid’s picture

vegantriathlete’s picture

Issue summary: View changes
Status: Closed (duplicate) » Needs work
Issue tags: -7.x-2.0 alpha blocker +7.x-2.0 beta blocker

This is not actually a duplicate. The referenced issue has a patch that just creates the whitelist. Whether Term reference is selected in the whitelist or not it does not appear as a field in the media browser for an image embedded via the wysiwyg.

The point of this issue to add the capability to override term references properly, not just to get rid of the error by not allowing the term references to be overridden.

vegantriathlete’s picture

Devin Carlson’s picture

Component: Code » Media WYSIWYG
Dave Reid’s picture

brockfanning’s picture

Status: Needs work » Needs review
FileSize
1.28 KB

This patch fixes the issue in the cases that I've tested, which are: single value fields of the types: term reference, entityreference, checkbox, and list (integers, strings, etc.). I suspect that it may not work with autocomplete widgets, but I have not tested that.

brockfanning’s picture

I should clarify: #9 above only works for single-value fields.

brockfanning’s picture

Status: Needs review » Needs work

Hmm, #9 may not be working. Let me investigate some more.

brockfanning’s picture

Status: Needs work » Needs review

False alarm, I guess something else was going on. Switching back to needs-reivew.

brockfanning’s picture

I haven't tested it too much, but here is a slight expansion to support multi-value fields, at least for select lists.

brockfanning’s picture

Title: Term reference fields are not being handled correctly when file is embedded in the WYSIWYG » Several types of fields are not being handled correctly when file is embedded in the WYSIWYG

joseph.olstad’s picture

Status: Needs review » Fixed

committed to dev 7.x-2.x

Status: Fixed » Closed (fixed)

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