You are here

function theme_image_url_formatter in Image URL Formatter 7

Returns HTML for an image url field formatter.

Parameters

array $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_image_url_formatter()
image_url_formatter_field_formatter_view in ./image_url_formatter.module
Implements hook_field_formatter_view().

File

./image_url_formatter.module, line 205
Add an URL formatter for image field

Code

function theme_image_url_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'];
  }

  // Return the URI path.
  if ($variables['url_type'] == 3) {
    return $item['uri'];
  }
  $output = file_create_url($item['uri']);
  if ($variables['image_style']) {
    $image['style_name'] = $variables['image_style'];
    $output = image_style_url($image['style_name'], $item['uri']);
  }
  $output = image_url_formatter_convert_full_url($output, $variables['url_type']);
  if ($variables['path']) {
    $path = $variables['path']['path'];
    $path = image_url_formatter_convert_full_url($path, $variables['url_type']);
    $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;
}