Consider the following code created by the WYSIWYG plugin:
[[{"type":"media","view_mode":"media_large","fid":"875","attributes":{"alt":"","class":"media-image image-style-large","height":"306","typeof":"foaf:Image","width":"408"}}]]
In media_token_to_markup() this will be decoded to a PHP array with the function drupal_json_decode(). You will end up with an array where $tag_info['attributes']['class']
is a string. This one is later used as the class attribute for a render array, but there the the type must be an array, not a string. This has been causing major issues in #1711746: Fatal error after updating from 3.x to 3.0.
I'm attaching a patch that will make the class attribute an array instead of a string.
Comment | File | Size | Author |
---|---|---|---|
media-7.x-2.x-fix-class-array.patch | 691 bytes | JimmyAx | |
Comments
Comment #1
marcoka CreditAttribution: marcoka commentedi can confirm this.
this happens with 1.2 too, hello WSOD.
used the patch, fixes it. its a fix of data that is just beeing provided the wrong way. maybe this should be fixed at the "root" of the problem.
Comment #2
JimmyAx CreditAttribution: JimmyAx commentedFixing it at the "root" of the problem would in this case probably mean to make the class attribute a json array. This would require you to modfy any existing database entries too. That might not be really feasible so this patch is probably easiest way to fix the bug.
Comment #3
marcoka CreditAttribution: marcoka commentedagree. just to note that i meant. its an effective fix that is pretty understandable. i always comment my code with //@todo ... thats what i meant
Comment #4
Jeff Burnz CreditAttribution: Jeff Burnz commentedThis should be critical, it causes a fatal error when other themes or modules correctly add a class to what should be an array.
Comment #5
Jeff Burnz CreditAttribution: Jeff Burnz commentedSimilar issue opened for User Badges module, just linking to for reference so others can find workarounds etc, this is looking like a more widespread issue and needs to be highlighted for module developers: #1748394: Class attributes should be an array, not a string
Comment #6
Dave ReidComment #7
Dave ReidCommitted to both 7.x-2.x and 7.x-1.x. Thanks!
http://drupalcode.org/project/media.git/commit/99fcf8b
http://drupalcode.org/project/media.git/commit/6709667