function theme_image_formatter

Returns HTML for an image field formatter.

Parameters

array $variables: An associative array containing:

  • item: An array of image data.
  • image_style: An optional image style.
  • path: An optional array containing the link 'path' and link 'options'.

Related topics

3 theme calls to theme_image_formatter()
ImageFormatter::viewElements in drupal/core/modules/image/lib/Drupal/image/Plugin/field/formatter/ImageFormatter.php
Implements \Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
ImageThemeFunctionTest::testImageFormatterTheme in drupal/core/modules/image/lib/Drupal/image/Tests/ImageThemeFunctionTest.php
Tests usage of the image field formatters.
theme_picture_formatter in drupal/core/modules/picture/picture.module
Returns HTML for a picture field formatter.

File

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

Code

function theme_image_formatter($variables) {
  $item = $variables['item'];

  // Do not output an empty 'title' attribute.
  if (isset($item['title']) && drupal_strlen($item['title']) == 0) {
    unset($item['title']);
  }
  if ($variables['image_style']) {
    $item['style_name'] = $variables['image_style'];
    $output = theme('image_style', $item);
  }
  else {
    $output = theme('image', $item);
  }

  // The link path and link options are both optional, but for the options to be
  // processed, the link path must at least be an empty string.
  if (isset($variables['path']['path'])) {
    $path = $variables['path']['path'];
    $options = isset($variables['path']['options']) ? $variables['path']['options'] : array();

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