You are here

link_image.module in Link Image Formatter 7

Same filename and directory in other branches
  1. 6 link_image.module

File

link_image.module
View source
<?php

/*
 * @file link_image.module
 * Defines a field formatter to display a link to an image as an HTML image
 * element.
 */

/**
 * Implements hook_field_formatter_info().
 */
function link_image_field_formatter_info() {
  return array(
    'link_image' => array(
      'label' => t('Image with link as source URL'),
      'field types' => array(
        'link_field',
      ),
    ),
  );
}

/**
 * Implements hook_field_formatter_view().
 */
function link_image_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  foreach ($items as $delta => $item) {
    $element[$delta] = array(
      '#theme' => 'link_image_formatter',
      '#element' => $item,
    );
  }
  return $element;
}

/**
 * Implements hook_theme().
 */
function link_image_theme() {
  return array(
    'link_image_formatter' => array(
      'variables' => array(
        'element' => NULL,
      ),
    ),
  );
}

/**
 * Returns HTML for an image caption field formatter.
 *
 * @param $variables
 *   An associative array containing:
 *   - item: An array of link data.
 *
 * @ingroup themeable
 */
function theme_link_image_formatter($vars) {
  $item = $vars['element'];
  $image = array(
    'path' => theme('link_formatter_link_plain', $vars),
  );

  // Do not output an empty 'title' attribute.
  if (drupal_strlen($item['title']) > 0) {
    $image['title'] = $item['title'];
    $image['alt'] = $item['title'];
  }
  $output = theme('image', $image);
  return $output;
}

Functions

Namesort descending Description
link_image_field_formatter_info Implements hook_field_formatter_info().
link_image_field_formatter_view Implements hook_field_formatter_view().
link_image_theme Implements hook_theme().
theme_link_image_formatter Returns HTML for an image caption field formatter.