Hello,
i'm trying to embed a youtube video in my template file. I have a special field called Video (field_field_video).
To show my video, i'm using the following code:
$my_media = $row->field_field_video[0]['raw']
theme('media_youtube_video', $my_media)
But it gives me a lot of errors:
Notice: Undefined index: autoplay in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: enablejsapi in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: loop in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: modestbranding in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: enablejsapi in media_youtube_preprocess_media_youtube_video() (line 34 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: loop in media_youtube_preprocess_media_youtube_video() (line 49 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: rel in media_youtube_preprocess_media_youtube_video() (line 55 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: showinfo in media_youtube_preprocess_media_youtube_video() (line 55 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: theme in media_youtube_preprocess_media_youtube_video() (line 65 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: theme in media_youtube_preprocess_media_youtube_video() (line 66 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: color in media_youtube_preprocess_media_youtube_video() (line 68 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: color in media_youtube_preprocess_media_youtube_video() (line 69 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: autohide in media_youtube_preprocess_media_youtube_video() (line 71 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: autohide in media_youtube_preprocess_media_youtube_video() (line 72 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: nocookie in media_youtube_preprocess_media_youtube_video() (line 76 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: protocol_specify in media_youtube_preprocess_media_youtube_video() (line 83 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: autoplay in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: enablejsapi in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: loop in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: modestbranding in media_youtube_preprocess_media_youtube_video() (line 30 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: enablejsapi in media_youtube_preprocess_media_youtube_video() (line 34 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: loop in media_youtube_preprocess_media_youtube_video() (line 49 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: rel in media_youtube_preprocess_media_youtube_video() (line 55 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: showinfo in media_youtube_preprocess_media_youtube_video() (line 55 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: theme in media_youtube_preprocess_media_youtube_video() (line 65 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: theme in media_youtube_preprocess_media_youtube_video() (line 66 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: color in media_youtube_preprocess_media_youtube_video() (line 68 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: color in media_youtube_preprocess_media_youtube_video() (line 69 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: autohide in media_youtube_preprocess_media_youtube_video() (line 71 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: autohide in media_youtube_preprocess_media_youtube_video() (line 72 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: nocookie in media_youtube_preprocess_media_youtube_video() (line 76 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
Notice: Undefined index: protocol_specify in media_youtube_preprocess_media_youtube_video() (line 83 of /Applications/MAMP/htdocs/bw/sites/all/modules/media_youtube/includes/themes/media_youtube.theme.inc).
It looks like i need to pass all those options using $my_media['options']['...'] and than it will work fine but i don't think it's a good solution, actually i'm quite sure that it's some kind of a bug or that i'm doing something wrong. Can you please advice me how it should be done?
Thanks in advance!
Comments
Comment #1
bajki CreditAttribution: bajki commentedPlease, help me. I'm creating an commercial project using this module and this issue is stopping me really hard.
Comment #2
RobW CreditAttribution: RobW commentedWhy not just
<?php print render($content['field_field_video']) ?>
in the normal D7 fashion? If you're trying to print a video in a template that it's not available in, take a look at entity metadata wrappers.Comment #3
B Leg CreditAttribution: B Leg commentedBecause
<?php print render($content['field_field_video']) ?>
doesn't do anything.Bajki did you figure this out? I've been looking for months for any documentation on calling the theme() function for this and it just doesn't exist.
Comment #4
bajki CreditAttribution: bajki commentedNope, not yet. I'm still searching for any clues.
Comment #5
andreasoby CreditAttribution: andreasoby commentedI'm looking as well. I'll keep you posted if I find a solution.
Comment #6
andreasoby CreditAttribution: andreasoby commentedThe last patch here helped me out. Also works for the Media Vimeo module with a little tweaking.
http://drupal.org/node/1884484
Comment #7
aspafford CreditAttribution: aspafford commentedI found it necessary to call media_youtube_variable_default() in my theme template. Otherwise the default options never seem to load, resulting in php notices.
print theme('media_youtube_video', array('uri'=>$video[0]['uri'], 'options'=>media_youtube_variable_default()));
Comment #8
As If CreditAttribution: As If commentedHere's how I did it with MYT version 7.x-2.0-rc4...
NOTE: field_youtube_video is the name of MY field. Yours is probably different.
Comment #9
jschrab CreditAttribution: jschrab commentedWas there an intentional change, or is 7.x-2.0-rc4 missing "includes/media_youtube.variables.inc" - so media_youtube_variable_default() is also missing?
Comment #10
hey_germanoRemoving that file was intentional, yes - here's the related issue/commits: https://www.drupal.org/node/2067955
To get the options array (values set at admin/structure/file-types/manage/video/file-display), you can use this:
Then use the theme function call like in #8.
Comment #11
Devin Carlson CreditAttribution: Devin Carlson commentedRobW's answer in #2 is correct.
To print a file entity (including a YouTube video):