You are here

function theme_photoswipe_image_formatter in PhotoSwipe 7.2

Same name and namespace in other branches
  1. 7 photoswipe.theme.inc \theme_photoswipe_image_formatter()

Returns HTML for an Photoswipe image field formatter.

Parameters

$variables: An associative array containing:

  • item: An array of image data.
  • image_style: An optional image style.
  • path: An array containing the link 'path' and link 'options'.
1 theme call to theme_photoswipe_image_formatter()
photoswipe_field_formatter_view in ./photoswipe.module
Implements hook_field_formatter_view().

File

./photoswipe.theme.inc, line 19
Photoswipe theme functions.

Code

function theme_photoswipe_image_formatter($variables) {
  $item = $variables['item'];
  $node = $variables['node'];
  $field = $variables['field'];
  $settings = $variables['display_settings'];
  $alt = !empty($item['alt']) ? $item['alt'] : '';
  $title = !empty($item['title']) ? $item['title'] : '';
  if (empty($alt) && !empty($item['field_file_image_alt_text'][LANGUAGE_NONE])) {
    $alt = $item['field_file_image_alt_text'][LANGUAGE_NONE][0]['value'];
  }
  if (empty($title) && !empty($item['field_file_image_title_text'][LANGUAGE_NONE])) {
    $title = $item['field_file_image_title_text'][LANGUAGE_NONE][0]['value'];
  }
  $image = array(
    'path' => $item['uri'],
    'alt' => $alt,
    'title' => $title,
    'style_name' => $settings['photoswipe_node_style'],
  );
  if ($variables['delta'] == 0 && !empty($settings['photoswipe_node_style_first'])) {
    $image['style_name'] = $settings['photoswipe_node_style_first'];
  }
  $dimensions = array();
  if (isset($item['width']) && isset($item['height'])) {
    $image['width'] = $dimensions['width'] = $item['width'];
    $image['height'] = $dimensions['height'] = $item['height'];
  }
  if ($style_name = $settings['photoswipe_image_style']) {
    $path = image_style_url($style_name, $image['path']);
    $dimensions = array(
      'width' => $item['width'],
      'height' => $item['height'],
    );
    image_style_transform_dimensions($style_name, $dimensions);
  }
  else {
    $path = file_create_url($image['path']);
  }

  // Set Caption for this image
  if (isset($settings['photoswipe_caption'])) {
    $caption_setting = $settings['photoswipe_caption'];
    switch ($caption_setting) {
      case 'alt':
        $caption = $image[$caption_setting];
        break;
      case 'title':
        $caption = $image[$caption_setting];
        break;
      case 'node_title':
        $caption = $node->title;
        break;
      default:
        $view_mode = $settings['photoswipe_view_mode'] ? $settings['photoswipe_view_mode'] : 'default';
        $field_view = field_view_field('node', $node, $caption_setting, $view_mode);
        $caption = drupal_render($field_view);
        break;
    }
  }
  else {
    $caption = $alt;
  }
  return theme('photoswipe_imagefield', array(
    'image' => $image,
    'path' => $path,
    'dimensions' => $dimensions['width'] . 'x' . $dimensions['height'],
    'caption' => $caption,
  ));
}