You are here

prettyphoto_formatters_image.module in prettyPhoto Formatters 7

prettyPhoto Image formatter hooks and callbacks.

File

modules/prettyphoto_formatters_image/prettyphoto_formatters_image.module
View source
<?php

/**
 * @file
 * prettyPhoto Image formatter hooks and callbacks.
 */

/**
 * Implements hook_field_formatter_info().
 */
function prettyphoto_formatters_image_field_formatter_info() {
  $formatters = array();
  $image = $pfi = image_styles();
  $types = array(
    'prettyphoto',
  );
  foreach ($types as $type) {
    foreach ($image as $image_key => $image_value) {
      $formatters['pfi__' . $type . '__' . $image_key . '__original'] = array(
        'label' => $type . ': ' . $image_key . '->original',
        'field types' => array(
          'image',
        ),
      );
      foreach ($pfi as $pfi_key => $pfi_value) {
        $formatters['pfi__' . $type . '__' . $image_key . "__" . $pfi_key] = array(
          'label' => $type . ': ' . $image_key . '->' . $pfi_key,
          'field types' => array(
            'image',
          ),
        );
      }
    }
  }
  return $formatters;
}

/**
 * Implements hook_field_formatter_view().
 */
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;
}

/**
 * Implements hook_theme().
 */
function prettyphoto_formatters_image_theme($existing, $type, $theme, $path) {
  $theme = array();
  $theme['prettyphoto_formatters_image'] = array(
    'variables' => array(
      'item' => NULL,
      'path' => NULL,
      'pfi_type' => NULL,
      'image_style' => NULL,
      'pfi_style' => NULL,
      'node_id' => NULL,
      'field_name' => NULL,
    ),
  );
  foreach ($theme as &$array) {
    $array['file'] = 'prettyphoto_formatters_image.formatter.inc';
  }
  return $theme;
}

/**
 * Implements filefield's hook_file_formatter_info().
 */
function prettyphoto_formatters_image_file_formatter_info() {
  return array(
    'prettyphoto_formatters_image' => array(
      'title' => t('prettyPhoto image'),
      'description' => t('Displays image files in a popup lightbox.'),
    ),
  );
}