You are here

function prettyphoto_formatters_image_field_formatter_view in prettyPhoto Formatters 7

Implements hook_field_formatter_view().

File

modules/prettyphoto_formatters_image/prettyphoto_formatters_image.module, line 37
prettyPhoto Image formatter hooks and callbacks.

Code

function prettyphoto_formatters_image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $pieces = explode('__', $display['type']);
  $pfi_type = $pieces[1];
  $image_style = $pieces[2];
  $pfi_style = $pieces[3];
  if ($image_style == 'original') {
    $image_style = NULL;
  }
  if ($pfi_style == 'original') {
    $pfi_style = NULL;
  }
  if ($entity_type == 'node') {
    $node_id = $entity->nid;
  }
  else {
    $node_id = NULL;
  }
  foreach ($items as $delta => $item) {
    $uri = array(
      'path' => file_create_url($item['uri']),
      'options' => array(),
    );
    if (isset($item['alt'])) {
      $item['alt'] = check_plain($item['alt']);
    }
    if (isset($item['title'])) {
      $item['title'] = check_plain($item['title']);
    }
    $element[$delta] = array(
      '#theme' => 'prettyphoto_formatters_image',
      '#item' => $item,
      '#pfi_type' => $pfi_type,
      '#image_style' => $image_style,
      '#pfi_style' => $pfi_style,
      '#path' => $uri,
      '#node_id' => $node_id,
      '#field_name' => $field['field_name'],
    );
  }
  return $element;
}