Problem/motivation

It is not possible to override all field types in the WYSIWYG. For example, if there is a taxonomy term reference field its value is not parsed correctly when rendered and causes the following error:


Recoverable fatal error: Object of class stdClass could not be converted to string in taxonomy_field_formatter_prepare_view() (line 1684 of 
modules/taxonomy/taxonomy.module).

Possible solutions

Rewrite the way that media_wysiwyg_filter_field_parser parsers the field values out of the markup JSON so that it more intelligently applies the values to the fields of the file. Perhaps using entity_metadata_wrapper from the entity module.

Comments

cato’s picture

More info on this, it would seem that it's passing bad arguments to taxonomy_field_formatter_prepare_view() when an embedded file has taxonomy fields that are filled in. If they are left blank, it works. If they are filled in, it crashes. Now, I don't know if this is related to file entity or if it's a media / mediabutton / media wysiwyg thing.

I added a watchdog log on the parameters passed in to taxonomy_field_formatter_prepare_view() just to see what's passed and it looks like this:

watchdog('testing hello','

entity_type='.$entity_type.', entities='.print_r($entities,true). ', field='. $field. ', instances='. $instances. '. langcode='. $langcode. 'items='. print_r($items,true). 'displays='. $displays. '

');

This one does not crash:

entity_type=file, entities=Array
(
    [387] => stdClass Object
        (
            [fid] => 387
            [uid] => 36
            [filename] => F4_VF000148_880.jpg
            [uri] => public://F4_VF000148_880.jpg
            [filemime] => image/jpeg
            [filesize] => 495284
            [status] => 1
            [timestamp] => 1384165527
            [type] => image
            [field_file_image_alt_text] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 
                                )

                        )

                )

            [field_file_image_title_text] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 
                                )

                        )

                )

            [field_description] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 
                                )

                        )

                )

            [field_category] => Array
                (
                )

            [field_tags] => Array
                (
                    [und] => 
                )

            [field_motive_id] => Array
                (
                )

            [field_title] => Array
                (
                )

            [field_creator] => Array
                (
                )

            [field_location] => Array
                (
                )

            [field_start] => Array
                (
                )

            [field_end] => Array
                (
                )

            [rdf_mapping] => Array
                (
                )

            [metadata] => Array
                (
                    [height] => 475
                    [width] => 880
                )

            [alt] => 
            [title] => 
            [override] => Array
                (
                    [attributes] => Array
                        (
                            [class] => Array
                                (
                                    [0] => media-element
                                    [1] => file-full
                                )

                        )

                    [fields] => Array
                        (
                            [field_description] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => 
                                                )

                                        )

                                )

                            [field_file_image_alt_text] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => 
                                                )

                                        )

                                )

                            [field_file_image_title_text] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => 
                                                )

                                        )

                                )

                            [field_tags] => Array
                                (
                                    [und] => 
                                )

                        )

                )

            [_field_view_prepared] => 1
        )

)
, field=Array, instances=Array. langcode=unditems=Array
(
    [387] => 
)
displays=Array

This one crashes:

entity_type=file, entities=Array
(
    [11] => stdClass Object
        (
            [fid] => 11
            [uid] => 1
            [filename] => Oskarshamn O3-reaktorhall-c 1012061949.jpg
            [uri] => public://Oskarshamn O3-reaktorhall-c 1012061949.jpg
            [filemime] => image/jpeg
            [filesize] => 258118
            [status] => 1
            [timestamp] => 1383503880
            [type] => image
            [field_file_image_alt_text] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => The reactor in Oskarshamns nuclear power plant
                                )

                        )

                )

            [field_file_image_title_text] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => The reactor in Oskarshamns nuclear power plant
                                )

                        )

                )

            [field_description] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => The reactor in Oskarshamns nuclear power plant.
                                )

                        )

                )

            [field_category] => Array
                (
                    [und] => Array
                        (
                            [] => 10
                        )

                )

            [field_tags] => Array
                (
                    [und] => nuclear, power, reactor, oskarshamn, sweden
                )

            [field_motive_id] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => Motive1234
                                    [format] => 
                                    [safe_value] => Motive1234
                                )

                        )

                )

            [field_title] => Array
                (
                )

            [field_creator] => Array
                (
                )

            [field_location] => Array
                (
                )

            [field_start] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => 1952
                                )

                        )

                )

            [field_end] => Array
                (
                )

            [rdf_mapping] => Array
                (
                )

            [metadata] => Array
                (
                    [height] => 1080
                    [width] => 1605
                )

            [alt] => The reactor in Oskarshamns nuclear power plant
            [title] => The reactor in Oskarshamns nuclear power plant
            [override] => Array
                (
                    [attributes] => Array
                        (
                            [alt] => The reactor in Oskarshamns nuclear power plant
                            [title] => The reactor in Oskarshamns nuclear power plant
                            [class] => Array
                                (
                                    [0] => media-element
                                    [1] => file-full
                                )

                        )

                    [fields] => Array
                        (
                            [field_description] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => The reactor in Oskarshamns nuclear power plant.
                                                )

                                        )

                                )

                            [field_file_image_alt_text] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => The reactor in Oskarshamns nuclear power plant
                                                )

                                        )

                                )

                            [field_file_image_title_text] => Array
                                (
                                    [und] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [value] => The reactor in Oskarshamns nuclear power plant
                                                )

                                        )

                                )

                            [field_category] => Array
                                (
                                    [und] => Array
                                        (
                                            [] => 10
                                        )

                                )

                            [field_tags] => Array
                                (
                                    [und] => nuclear, power, reactor, oskarshamn, sweden
                                )

                        )

                )

            [_field_view_prepared] => 1
        )

)
, field=Array, instances=Array. langcode=unditems=Array
(
    [11] => Array
        (
            [] => 10
        )

)
displays=Array

Also, there are a number of errors in the same taxonomy_field_formatter_prepare_view leading up to the final Recoverable Fatal Error and they are "illegal string offset 'tid'" and "illegal string offset 'taxonomy_term'"
The last error that occurs and that crashes the content view / listing is

Recoverable fatal error: Object of class stdClass could not be converted to string in taxonomy_field_formatter_prepare_view() (line 1685 of /var/www/clients/client1/web33/web/modules/taxonomy/taxonomy.module).

Appreciate any and all input on this issue as it is holding us back in development

cato’s picture

Update: It seems that multi-language was turned on somewhere in the development process and that some nodes were left as "language neutral" and some were in English.

Nodes that are Language Neutral crash when the Media Button is used. Nodes that are English do not crash.
Go figure...

mcjim’s picture

If you turn off the display of the taxonomy term (assuming it's on), do the errors go away?

You'll find this at Structure > File Types > (your file type) > Manage Display.

johnennew’s picture

Title: Activating Media button causes content error » Allow any field type to be overridden in media
Version: 7.x-2.0-alpha3 » 7.x-2.x-dev
Component: Media Browser » Media WYSIWYG
Assigned: Unassigned » johnennew
Issue summary: View changes
StatusFileSize
new4.71 KB

I've rewritten the title and description of this problem and supply a patch for review.

This places a dependency on entity because of the use of entity_metadata_wrapper which may not be necessary, but I think the pattern is neat.

johnennew’s picture

Issue summary: View changes
Status: Active » Needs review

Status: Needs review » Needs work
johnennew’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
johnennew’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes

Hmm.. cant seem to get the tests to fail locally.

Please find a better patch which allows multi value fields as well.

johnennew’s picture

and heres the patch in 10 again with some content.

Status: Needs review » Needs work
johnennew’s picture

Assigned: johnennew » Unassigned

Weird, these tests don't fail on me locally - any ideas?

Anonymous’s picture

"If you turn off the display of the taxonomy term (assuming it's on), do the errors go away?"

Yes.

dkingofpa’s picture

heddn’s picture

Category: Bug report » Feature request
Priority: Critical » Major
Status: Needs work » Closed (duplicate)
Related issues: +#2062721: Add a white list of file fields that can be overwritten when the file is added in the wysiwyg

Closing as duplicate of #2062721: Add a white list of file fields that can be overwritten when the file is added in the wysiwyg. BTW, I tested this on my local with taxonomy terms and the approach here simply doesn't work, even with the addition of entity api. Example: taxonomy term tags that auto-create fail.

vegantriathlete’s picture

brockfanning’s picture

Since there are several version of this issue that have been closed, just posting an FYI that I made a patch here: #2062365-9: Several types of fields are not being handled correctly when file is embedded in the WYSIWYG.

mibfire’s picture

  $file_wrapper->{$field_name} = $field_value;

There is error when $field_value is empty. I fixed this in the attached patch.