Download & Extend

Media filter is using string instead of array for the class attribute

Project:Media
Version:7.x-2.0-unstable6
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)
Issue tags:Media Initiative, sprint

Issue Summary

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.

AttachmentSizeStatusTest resultOperations
media-7.x-2.x-fix-class-array.patch691 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 0 pass(es).View details

Comments

#1

i 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.

#2

Fixing 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.

#3

agree. 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

#4

Priority:major» critical

This should be critical, it causes a fatal error when other themes or modules correctly add a class to what should be an array.

#5

Similar 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

#6

#7

Status:needs review» fixed

Committed 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

#8

Status:fixed» closed (fixed)

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

nobody click here