How to render a Youtube thumbnail in a template in Drupal 7

后端 未结 3 1434
Happy的楠姐
Happy的楠姐 2021-02-08 03:41

I am using the following modules:

  • media
  • media_youtube
  • Styles

and would like to render a thumbnail of a Youtube video in a templa

3条回答
  •  情话喂你
    2021-02-08 03:54

    Digging around in the media_youtube module code there's a function that will build this up for you in includes/media_youtube.formatters.inc called media_youtube_file_formatter_image_view(). You can use code like the following to render the thumbnail image:

    // Make sure the correct include file is loaded
    module_load_include('inc', 'media_youtube', '/includes/media_youtube.formatters.inc');
    
    // Load the file
    $file = file_load($my_media['fid']);
    
    // Set up the settings array with your image style
    $display['settings'] = array('image_style' => 'unlinked_thumbnail');
    
    // Get the render array for the thumbnail image
    $image_render_array = media_youtube_file_formatter_image_view($file, $display, LANGUAGE_NONE);
    
    // Render it
    print render($image_render_array);
    

提交回复
热议问题