Hi all,
When i embed a youtube video in the body of a node using the WYSIWYG/TinyMce combo - through the media button - i get the following errors when saving the node.
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in media_youtube_preprocess_media_youtube_video() (regel 98 van media_youtube.theme.inc).
Warning: implode() [function.implode]: Invalid arguments passed in template_process() (regel 2404 van includes/theme.inc).Now, while debugging this , i noticed in media_youtube.theme.inc that the following is happening on #97:
if (isset($variables['options']['attributes']['class'])) {
$variables['classes_array'] = array_merge($variables['classes_array'], $variables['options']['attributes']['class']);
}
It's easy to conclude what is causing the error: $variables['options']['attributes']['class'] is a string, not an array.
That's because the media module passes this on as a string when converting the meda tags with media_token_to_markup().
I'm providing a patch so that the class is added to the array, instead of merged. I could have exploded the class, but while briefly looking through the code, i never saw that it ever could be a array (....? if this wrong, please say so).
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | 1797668_13-media_youtube-errors-when-submitting-content.patch | 972 bytes | cweagans |
| #1 | media_youtube-array_merge_fix-1797668-1.patch | 751 bytes | 30equals |
Comments
Comment #1
30equals commentedOk, here's the patch....
Comment #2
willieseabrook commentedWith 7.x-2.0-rc1 I received the same error:
I confirm that i've tested the attached patch in #1 fixes the error. Thanks @30equals.
Comment #3
RobW commentedI think there is some editor or module inconsistency happening here. The current code is working with CKEditor, and the latest WYSIWYG and Media modules.
The class key is an array in my install. In
media_youtube_file_formatter_video_view()in formatters.inc,$element[#options][attributes][class]is a sequential array with class names. This feeds to the theme.inc preprocess function where$variables[#options][attributes][class]is the same array.Can you check with dpm() or a var dump what the class key contains for you in these places? Also, if you can paste your shortcode we can make sure that they're the same in both of our installs. After being floated right with the WYSIWYG button, mine (with line breaks added for readability) looks like:
[[{"type":"media","view_mode":"wysiwyg","fid":"30",
"attributes":{"alt":"My alt","class":"media-image media-image-right",
"style":"float: right; ","typeof":"foaf:Image"}}]]
I've also confirmed this works with direct editing of the class section of the shortcode.
Thanks for the testing and work here. My suspicion is that TinyMCE is doing something weird with the shortcode, or there's a module change between Media or WYSIWYG release and dev versions that is breaking this.
Comment #4
RobW commentedThis is the only issue I'm looking at right now as a stable release blocker. Any TinyMCE users able to provide feedback?
Comment #5
themusician commentedThe patch supplied by post #1 works great. I too received the following error messages when trying to insert two youtube videos using the ckeditor library for wysiwyg.
Warning: array_merge(): Argument #2 is not an array in media_youtube_preprocess_media_youtube_video()
Warning: implode(): Invalid arguments passed in template_process() (line 2404 of /path_to_site/includes/theme.inc).
Both warnings appear for each video attempted to be inserted. The patch fixes this.
Comment #6
RobW commentedThanks for the report that this is a problem with CKEditor too. Can you tell me what versions of media and wysiwyg you're using? The patch breaks on my testing site, while the current code works.
Comment #7
themusician commentedwysiwyg: 7.x-2.1
Media: 7.x-1.2
Media YouTube: 7.x-2.0-rc1
ckeditor library version: 3.6.4.7575
Drupal 7.15
I hope that helps and please let me know if you other information is required.
Comment #8
Anonymous (not verified) commentedI wanted to throw this out there that although the error displays after hitting the save or preview button, the error does not display after refreshing a saved node.
Comment #9
RobW commentedI haven't had a chance to look into this any deeper, but I'm almost positive this is a discrepancy between Media 1.x and 2.x. We'll probably just need some wrapper code to test if the class array is a string, and if so explode() it into an array.
Comment #10
mxtI'm a TinyMCE user and I can confirm that patch provided in #1 resolve the issue.
Comment #11
cweagansI'm working on this today.
Comment #12
RobW commentedcweagans, you should be able to use the final code sample in this comment: http://drupal.org/node/1240976#comment-6615888. I would have commited already, but haven't had time to test with clean installs of Media 1.x and 2.x.
Comment #13
cweagansYou're right. I was thinking that there might be some circumstance where `$variables['options']['attributes']['class']` could be a space-separated list of classes or something, but it looks like the code you pointed out will do the trick. Patch attached.
Comment #14
willvincent commented#13 works well, making RTBC
Comment #15
willvincent commentedThe change had to be applied by hand to rc1 release, so updating version to dev branch that patch is written for
Comment #16
RobW commentedThanks everyone. Committed: http://drupalcode.org/project/media_youtube.git/commit/f2a44ea
Comment #17
stratos commentedCould you explain how to apply that patch? i dont understand how it works.. thx!
Comment #18
stratos commentedCould you explain how to apply that patch? i dont understand how it works.. thx!
Comment #19
RobW commented@stratos: Check out the git documentation page here http://drupal.org/node/1399218 for instructions. If a maintainer chimes in and says a patch has been "committed", the patch has become part of the latest development release, which you can download on the project page.
Comment #20
willieseabrook commented@stratos
You can apply the patch following the instructions in the link @RobW has provided.
But now that Rob has added the patch to the module, there is an easier way - you can simply download the latest release.
Go to the module page at http://drupal.org/project/media_youtube, but don't download the green release, download the red release "7.x-2.x-dev" from October 28.
Once you have downloaded, delete the folder containing the module, and then replace them with the files in the new download.