Skip navigation
Help

theme_image_formatter

7 image.field.inc theme_image_formatter($variables)

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'.

Related topics

File

drupal/modules/image/image.field.inc, line 531
Implement an image field, based on the file module's file field.

Code

function theme_image_formatter($variables) {
  $item = $variables['item'];
  $image = array(
    'path' => $item['uri'], 
    'alt' => $item['alt'],
  );
  // Do not output an empty 'title' attribute.
  if (drupal_strlen($item['title']) > 0) {
    $image['title'] = $item['title'];
  }

  if ($variables['image_style']) {
    $image['style_name'] = $variables['image_style'];
    $output = theme('image_style', $image);
  }
  else {
    $output = theme('image', $image);
  }

  if ($variables['path']) {
    $path = $variables['path']['path'];
    $options = $variables['path']['options'];
    // When displaying an image inside a link, the html option must be TRUE.
    $options['html'] = TRUE;
    $output = l($output, $path, $options);
  }

  return $output;
}