You are here

function slick_get_media_thumbnail in Slick Carousel 7.2

Format image/media file data, called by Media file and Field collection.

1 call to slick_get_media_thumbnail()
slick_extract_media_data in includes/slick.extras.inc
Gets a media URL from the rendered iframe already containing all the params.

File

includes/slick.extras.inc, line 71
Contains optional functions called by frontend Media, or Field collection.

Code

function slick_get_media_thumbnail(array &$settings, array &$media = array()) {
  $image_uri = '';
  if (!slick_is_media($media['scheme'])) {
    return $image_uri;
  }

  // Ensures disabling Media sub-modules while being used doesn't screw up.
  try {
    $wrapper = file_stream_wrapper_get_instance_by_uri($media['media_uri']);
    if (!is_object($wrapper)) {
      throw new Exception('Unable to find matching wrapper');
    }
    $parts = $wrapper
      ->get_parameters();
    $media_id = '';
    switch ($media['scheme']) {
      case 'vimeo':
      case 'youtube':
        $media_id = $parts['v'];
        break;
      case 'soundcloud':
        $media_id = $parts['u'];
        break;
    }
    $image_uri = $wrapper
      ->getLocalThumbnailPath();
    $media['media_id'] = $media_id;
    if ($media_id) {
      $id = drupal_html_id('media-' . $media['scheme'] . '-' . $media_id);
      $settings['content_attributes']['id'] = $id;
    }
  } catch (Exception $e) {
    watchdog('slick', 'Unable to render media from %uri. Error: %error', array(
      '%uri' => $media['media_uri'],
      '%error' => $e
        ->getMessage(),
    ));
    return '';
  }
  return $image_uri;
}