I just upgraded the module from 7.x-1.0-beta3 to 7.x-3.0 (and Media module from v1.4 to v1.5) and now when viewing a node I got about 30 undefined index errors, because media_youtube_preprocess_media_youtube_video() assumed all the keys would be present, and most of them are not. In fact, it looks like they were all deliberately deleted in media_youtube_update_7203()!

I was able to prevent all the undefined index errors by adding isset() calls in the code, as in the attached patch.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jenlampton’s picture

Issue summary: View changes
jenlampton’s picture

Issue summary: View changes
das-peter’s picture

+++ b/themes/media_youtube.theme.inc
@@ -29,11 +29,11 @@ function media_youtube_preprocess_media_youtube_video(&$variables) {
-    if ($variables['options'][$option]) {
+    if (isset($variables['options'][$option])) {
       $query[$option] = 1;
     }

How about using something like:

$query[$option] = (int) !empty($variables['options'][$option])

Less code
No notices if an option is missing.
Explicit option set to 0 / 1 - defaults to 0 if an option is missing, Currently it looks like I can't disable autoplay - because if the autoplay option is set but is 0 - I still get $query[$option] = 1;

das-peter’s picture

  1. +++ b/themes/media_youtube.theme.inc
    @@ -48,13 +48,13 @@ function media_youtube_preprocess_media_youtube_video(&$variables) {
    +  if (isset($variables['options']['loop'])) {
    

    Just struggled with this - I guess this should be if (!empty($variables['options']['loop'])) {

  2. +++ b/themes/media_youtube.theme.inc
    @@ -86,14 +86,14 @@ function media_youtube_preprocess_media_youtube_video(&$variables) {
    -  if ($variables['options']['nocookie']) {
    ...
    -  if ($variables['options']['protocol_specify']) {
    +  if (isset($variables['options']['protocol_specify'])) {
    

    I guess these also should use !empty().