Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 567 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to render a Youtube thumbnail in a template in Drupal 7

#1
I am using the following modules:

- media
- media_youtube
- Styles

and would like to render a thumbnail of a Youtube video in a template (.tpl). Which theme function should I use and with what params?

My best quess would be something like:

$my_media['style_name'] = 'unlinked_thumbnail';
print theme('file_styles',$my_media);

where $my_media is an array containing fid,uri,filename,filemime etc.

Since i'm very new to Drupal, all my attempts to make sense of the modules source code have failed. I feel like I have tried all possible combinations of style names defined in the youtube and styles module without getting any output.

Rendering the video itself however works just fine using

print theme('media_youtube_video',$my_media);

How do you guys do it?
Reply

#2
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);
Reply

#3
And if you want to print both thumb+video you could do this :

<?php print render($content['field_your_field']); ?>

If you in a tpl and want to use $variables - it will be something like:

<?php print render($variables['content']['field_url']['#object']->content['field_video']);?>

Hopu u can use it...
Reply

#4
One more example, which makes possible to render video thumbnail (vimeo, youtube, qbrick, etc.) with your custom image style.

`$file` - File object that you can easily get from media field.

$wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
$image_uri = $wrapper->getLocalThumbnailPath();

$image_rendered = theme('image_style', array(
'style_name' => 'YOUR_IMAGE_STYLE_HERE',
'path' => $image_uri
));

Please note, that if you want to render also image, than you need to check `$file->type` if it's `video` or `image`, because it will use different wrapper objects with different methods.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through