You are here

function cookie_content_blocker_media_get_preview in Cookie Content Blocker 7

Get the (local) preview for a blocked media file.

Parameters

object $file: The file object to retrieve a thumbnail for.

Return value

array The preview render array.

1 call to cookie_content_blocker_media_get_preview()
cookie_content_blocker_media_file_view in modules/cookie_content_blocker_media/cookie_content_blocker_media.module
Implements hook_file_view().

File

modules/cookie_content_blocker_media/cookie_content_blocker_media.module, line 123
Contains the main module code for Cookie content blocker - Media.

Code

function cookie_content_blocker_media_get_preview($file) {
  $wrapper = file_stream_wrapper_get_instance_by_uri($file->uri);
  if (empty($wrapper) || !is_callable(array(
    $wrapper,
    'getLocalThumbnailPath',
  ))) {
    return array();
  }
  try {
    $provider = cookie_content_blocker_media_get_provider($file);
  } catch (MediaInternetNoHandlerException $e) {
    return array();
  }
  if (empty($provider)) {
    return array();
  }
  return array(
    '#theme' => 'image_style',
    '#style_name' => cookie_content_blocker_media_provider_variable_get($provider, 'preview_style', 'blocked_media_teaser'),
    '#path' => $wrapper
      ->getLocalThumbnailPath(),
    '#alt' => $file->override['attributes']['alt'] ?? $file->filename,
  );
}