| 7 image.field.inc | theme_image_formatter($variables) |
| 8 image.field.inc | theme_image_formatter($variables) |
Returns HTML for an image field formatter.
Parameters
$variables: An associative array containing:
- item: Associative array of image data, which may include "uri", "alt", "width", "height", "title" and "attributes".
- image_style: An optional image style.
- path: An array containing the link 'path' and link 'options'.
Related topics
1 theme call to theme_image_formatter()
File
- modules/
image/ image.field.inc, line 599 - 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'],
);
if (isset($item['attributes'])) {
$image['attributes'] = $item['attributes'];
}
if (isset($item['width']) && isset($item['height'])) {
$image['width'] = $item['width'];
$image['height'] = $item['height'];
}
// 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 (!empty($variables['path']['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;
}
Login or register to post comments
Comments
Where are attributes?
Hi all,
There is a difference between the API version e the 7.12 version of this function:
$image = array(
'path' => $item['uri'],
'alt' => $item['alt'],
);
// Here was the passing on of the attributes array...
if (isset($item['width']) && isset($item['height'])) {
$image['width'] = $item['width'];
$image['height'] = $item['height'];
}
The attributes array is no more passed on. So, for example, you cannot add an ID attribute to the image.
Here there is a solution: http://stackoverflow.com/a/8930694. Anybody has better suggestions?
Fixed
This has been fixed in the development snapshot and will be part of the next release 7.14: http://drupal.org/node/1329586