You are here

function brightcove_media_file_formatter_image_view in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove_media/brightcove_media.module \brightcove_media_file_formatter_image_view()
  2. 7.2 brightcove_media/brightcove_media.module \brightcove_media_file_formatter_image_view()
  3. 7.3 brightcove_media/brightcove_media.module \brightcove_media_file_formatter_image_view()
  4. 7.4 brightcove_media/brightcove_media.module \brightcove_media_file_formatter_image_view()

The brightcove_media_image file formatter view callback.

1 string reference to 'brightcove_media_file_formatter_image_view'
brightcove_media_file_formatter_info in brightcove_media/brightcove_media.module
Implements hook_file_formatter_info().

File

brightcove_media/brightcove_media.module, line 307
This module provide the hook implementations for the integration with Media module.

Code

function brightcove_media_file_formatter_image_view($file, $display, $langcode) {
  $scheme = file_uri_scheme($file->uri);
  if ($scheme === BRIGHTCOVE_EMBED_TYPE_VIDEO || $scheme === BRIGHTCOVE_EMBED_TYPE_PLAYLIST) {
    $video = NULL;
    $items = brightcove_media_parse_uri($file->uri, TRUE);
    $account = $items['account'];
    $id = $items['id'];
    $path = brightcove_try_client($account, function ($client) use ($id, $scheme) {

      /** @var $cms \Brightcove\API\CMS */
      list($cms) = brightcove_create_classes($client);
      switch ($scheme) {
        case BRIGHTCOVE_EMBED_TYPE_VIDEO:
          $video = $cms
            ->getVideo($id);
          $images = $video
            ->getImages();
          if (isset($images['thumbnail'])) {
            return $images['thumbnail']
              ->getSrc();
          }
          break;
        case BRIGHTCOVE_EMBED_TYPE_PLAYLIST:
          $videos = $cms
            ->getVideosInPlaylist($id);
          foreach ($videos as $video_id) {
            $video = $cms
              ->getVideo($video_id);
            $images = $video
              ->getImages();
            if (isset($images['thumbnail'])) {
              return $images['thumbnail']
                ->getSrc();
            }
          }
          break;
      }
      return NULL;
    }) ?: brightcove_get_default_image();
    if (empty($display['settings']['image_style'])) {
      $element = [
        '#theme' => 'image',
        '#path' => $path,
      ];
    }
    else {
      $styled_path = image_style_path($display['settings']['image_style'], $path);
      $style = image_style_load($display['settings']['image_style']);
      image_style_create_derivative($style, $path, $styled_path);
      $element = [
        '#theme' => 'image_style',
        '#path' => $path,
        '#style_name' => $display['settings']['image_style'],
      ];
    }
    return $element;
  }
  return NULL;
}