You are here

function theme_linkimage_formatter in Link Image Field 7

Returns HTML for an image field formatter.

Parameters

$variables: An associative array containing:

  • item: An array of image data.
  • image_style: An optional image style.
  • path: An array containing the link 'path' and link 'options'.
1 theme call to theme_linkimage_formatter()
linkimagefield_field_formatter_view in ./linkimagefield.module
Implements hook_field_formatter_view().

File

./linkimagefield.module, line 369
Defines a link image field type.

Code

function theme_linkimage_formatter($variables) {
  $item = $variables['item'];
  $image = array(
    'path' => $item['uri'],
    'alt' => $item['alt'],
  );

  // Gets image height and width attributes.
  if (isset($item['width']) && isset($item['height'])) {
    $image['width'] = $item['width'];
    $image['height'] = $item['height'];
  }

  // Gets image 'longdesc' attribute.
  if (drupal_strlen($item['longdesc']) > 0) {
    $image['longdesc'] = $item['longdesc'];
  }

  // Gets anchor 'title' attribute.
  if (drupal_strlen($item['title']) > 0) {
    $image['title'] = $item['title'];
  }

  // Gets anchor 'rel' attribute.
  if (drupal_strlen($item['rel']) > 0) {
    $image['rel'] = $item['rel'];
  }

  // Gets anchor 'class' attribute.
  if (drupal_strlen($item['class']) > 0) {
    $image['class'] = $item['class'];
  }
  if ($variables['image_style']) {
    $image['style_name'] = $variables['image_style'];
    $output = theme('image_style', $image);
  }
  else {
    $output = theme('image', $image);
  }

  // Themes attributes for the anchor tag
  if ($item['url']) {
    $options = array(
      'html' => TRUE,
      'attributes' => array(
        'title' => $item['title'],
        'target' => $item['target'],
        'rel' => $item['rel'],
        'class' => $item['class'],
      ),
    );
    $output = l($output, $item['url'], $options);
  }
  return $output;
}