You are here

function theme_lightbox2_image in Lightbox2 7

Same name and namespace in other branches
  1. 8 lightbox2.formatter.inc \theme_lightbox2_image()
  2. 5.2 lightbox2.module \theme_lightbox2_image()
  3. 6 lightbox2.formatter.inc \theme_lightbox2_image()
  4. 7.2 lightbox2.formatter.inc \theme_lightbox2_image()

Theme function for displaying the lightbox2 trigger image in an imagefield.

Parameters

$path: The path to the image to be displayed.

$alt: The image alternative text.

$title: The image title.

$attributes: An array of image attributes, e.g. class name.

Return value

HTML output for displaying the image.

1 theme call to theme_lightbox2_image()
lightbox2_field_formatter_view in ./lightbox2.module
Implements hook_field_formatter_view().

File

./lightbox2.formatter.inc, line 24
Lightbox2 formatter hooks and callbacks.

Code

function theme_lightbox2_image($variables) {
  $path = $variables['path'];
  $item = $variables['item'];
  $image_style = $variables['image_style'];
  $node_id = $variables['node_id'];
  $field_name = $variables['field_name'];
  $caption = $variables['caption'];
  if (!$variables["lightbox_style"]) {
    $path['path'] = file_create_url($item['uri']);
  }
  else {
    $path['path'] = image_style_url($variables["lightbox_style"], $item['uri']);
  }

  // Lightbox type
  $rel = $variables['lightbox_type'];

  // Grouping
  $rel .= '[';
  $group = variable_get('lightbox2_image_group_node_id', 1);
  switch ($group) {

    // No groups
    case '0':
      break;

    // Group by field name
    case '1':
      $rel .= $field_name;
      break;

    // Group by node id
    case '2':
      $rel .= $node_id;
      break;

    // Group by field name and node id
    case '3':
      $rel .= $field_name . '_' . $node_id;
      break;

    // All nodes and fields in same group
    case '4':
      $rel .= 'group';
      break;
  }
  $rel .= ']';

  // Title Start
  $rel .= '[';
  switch ($caption) {
    case 'hidden':
      break;
    case 'filename':
      $rel .= $item['filename'];
      break;
    case 'title':
      $rel .= $item['title'];
      break;
    default:
      $caption_display = array(
        'label' => 'hidden',
      );
      $entity = entity_load('file', array(
        $item['fid'],
      ));
      $entity = $entity[$item['fid']];
      $renderable_field = field_view_field('file', $entity, $caption, $caption_display);
      $rel .= drupal_render($renderable_field);
      break;
  }

  // Download Link
  if (user_access('download original image')) {
    $url_download = file_create_url($item['uri']);
    $download_original_text = t(variable_get('lightbox2_download_link_text', 'Download Original'));
    $options_download = array();
    $options_download['attributes']['title'] = $download_original_text;
    $options_download['attributes']['download'] = '';
    $rel .= '<p>' . l($download_original_text, $url_download, $options_download) . '</p>';
  }

  // Title End
  $rel .= ']';
  $path['options']['attributes']['rel'] = $rel;
  $path['options']['attributes']['title'] = $item['title'];
  return theme('image_formatter', array(
    'item' => $item,
    'path' => $path,
    'image_style' => $image_style,
  ));
}