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:

<?php
$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

bajki’s picture

Please, help me. I'm creating an commercial project using this module and this issue is stopping me really hard.

RobW’s picture

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

B Leg’s picture

Because <?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.

bajki’s picture

Nope, not yet. I'm still searching for any clues.

andreasok’s picture

I'm looking as well. I'll keep you posted if I find a solution.

andreasok’s picture

The last patch here helped me out. Also works for the Media Vimeo module with a little tweaking.
http://drupal.org/node/1884484

aspafford’s picture

I 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()));

As If’s picture

Here's how I did it with MYT version 7.x-2.0-rc4...

$lang = LANGUAGE_NONE;
if(isset($node->field_youtube_video[$lang][0]['uri'])) {
    $options = array(
        'width' => 480,
        'height' => 300,
        'autohide' => 2,
        'autoplay' => 0,
        'color' => 'black',
        'enablejsapi' => 0,
        'loop' => 0,
        'modestbranding' => 0,
        'nocookie' => 0,
        'origin' => '',
        'protocol' => 'https:',
        'protocol_specify' => 0,
        'rel' => 1,
        'showinfo' => 1,
        'theme' => 'dark',
        'attributes' => Array()
    );
    $video = theme('media_youtube_video', array('uri'=>$node->field_youtube_video[$lang][0]['uri'], 'options'=>$options));
    echo $video;
}

NOTE: field_youtube_video is the name of MY field. Yours is probably different.

jschrab’s picture

Was 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?

hey_germano’s picture

Removing 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:

<?php
  $display
= file_displays('video', $view_mode = 'media_youtube');
 
$options = $display['media_youtube_video']['settings'];
?>

Then use the theme function call like in #8.

Devin Carlson’s picture

Status:Active» Fixed

RobW's answer in #2 is correct.

To print a file entity (including a YouTube video):

<?php
$file
= file_load($fid); // Load the file with the specified ID.
$build = file_view($file) // Build a render array from the loaded file.
print drupal_render($build); // Render the array and print out the resulting HTML.
?>