You are here

function lightbox2_field_formatter_view in Lightbox2 7

Same name and namespace in other branches
  1. 8 lightbox2.module \lightbox2_field_formatter_view()
  2. 7.2 lightbox2.module \lightbox2_field_formatter_view()

Implements hook_field_formatter_view().

Temporarily a (pretty much) straight copy of image's

File

./lightbox2.module, line 1048
Enables the use of lightbox2 which places images above your current page, not within. This frees you from the constraints of the layout, particularly column widths.

Code

function lightbox2_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display["settings"];
  $lightbox_type = $settings['type'];
  $image_style = $settings['image_style'];
  $lightbox_style = $settings['lightbox_style'];
  if ($image_style == 'original') {
    $image_style = NULL;
  }
  if ($lightbox_style == 'original') {
    $lightbox_style = NULL;
  }
  $wrapper = entity_metadata_wrapper($entity_type, $entity);
  foreach ($items as $delta => $item) {
    $uri = array(
      'path' => file_create_url($item['uri']),
      'options' => array(),
    );
    $element[$delta] = array(
      '#theme' => 'lightbox2_image',
      '#item' => $item,
      '#lightbox_type' => $lightbox_type,
      '#image_style' => $image_style,
      '#lightbox_style' => $lightbox_style,
      '#path' => $uri,
      '#node_id' => $wrapper
        ->getIdentifier(),
      '#field_name' => $field['field_name'],
      '#caption' => $settings['caption'],
    );
  }
  return $element;

  /*$element = array();

    // Check if the formatter involves a particular image style.
    //$matches = array();
    //if (preg_match('/__([a-z0-9_]+)/', $display['type'], $matches)) {
    //  $image_style = $matches[1];
    //}

    $pieces = explode('__', $display);
    $image_style = $pieces[2];
    // Temporary hardcoding link_file and image_style for debugging
    //$image_style = 'thumbnail';
    $link_file = TRUE;

    foreach ($items as $delta => $item) {
      if (isset($link_file)) {
        $uri = array(
          'path' => file_create_url($item['uri']),
          'options' => array(),
        );
      }
      $element[$delta] = array(
        '#theme' => 'lightbox2_image',
        '#item' => $item,
        '#image_style' => isset($image_style) ? $image_style : '',
        '#path' => isset($uri) ? $uri : '',
      );
    }

    return $element;*/
}