You are here

function theme_youtube_thumbnail in YouTube Field 7

Theme function for thumbnails.

1 theme call to theme_youtube_thumbnail()
youtube_field_formatter_view in ./youtube.module
Implements hook_field_formatter_view().

File

./youtube.theme.inc, line 145
Theme functions for the YouTube field module.

Code

function theme_youtube_thumbnail($variables) {
  $video_id = $variables['video_id'];
  $style = $variables['image_style'];
  $uri = youtube_build_thumbnail_uri($video_id);

  // Check to see if a thumbnail exists locally.
  if (!file_exists($uri)) {

    // Retrieve the image from YouTube.
    if (!youtube_get_remote_image($video_id)) {

      // Use the remote source if local copy fails.
      $src = youtube_build_remote_image_path($video_id);
      return theme('image', array(
        'path' => $src,
      ));
    }
  }
  $alt = t('Embedded thumbnail');
  if (!empty($variables['entity_title'])) {
    $alt .= ' ' . t('for @entity_title', array(
      '@entity_title' => $variables['entity_title'],
    ));
  }
  if ($style) {
    $image = theme('image_style', array(
      'style_name' => $style,
      'path' => $uri,
      'alt' => $alt,
    ));
  }
  else {
    $image = theme('image', array(
      'path' => $uri,
      'alt' => $alt,
    ));
  }

  // Check if a URL path is provided.
  if ($variables['image_link'] != NULL) {
    $url_path = $variables['image_link']['path'];
    $options = $variables['image_link']['options'];
    $image = l($image, $url_path, $options);
  }
  return $image;
}