function imagecache_external_field_formatter_view in Imagecache External 7.2
Implements hook_field_formatter_view().
File
- ./
imagecache_external.module, line 159 - Allows the usage of Image Styles on external images.
Code
function imagecache_external_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
// Check if the formatter involves a link.
if ($display['settings']['imagecache_external_link'] == 'content') {
$uri = entity_uri($entity_type, $entity);
}
elseif ($display['settings']['imagecache_external_link'] == 'file') {
$link_file = TRUE;
}
// Check if the field provides a title.
if ($field['type'] == 'link_field') {
if ($instance['settings']['title'] != 'none') {
$field_title = TRUE;
}
}
foreach ($items as $delta => $item) {
// Set path and alt text.
$image_alt = '';
if ($field['type'] == 'link_field') {
$image_path = imagecache_external_generate_path($item['url']);
// If present, use the Link field title to provide the alt text.
if (isset($field_title)) {
// The link field appends the url as title when the title is empty.
// We don't want the url in the alt tag, so let's check this.
if ($item['title'] != $item['url']) {
$image_alt = isset($field_title) ? $item['title'] : '';
}
}
}
else {
$image_path = imagecache_external_generate_path($item['value']);
}
$image_info = image_get_info($image_path);
$image_item = array(
'uri' => $image_path,
'width' => $image_info['width'],
'height' => $image_info['height'],
'alt' => $image_alt,
'title' => '',
);
if (isset($link_file)) {
$uri = array(
'path' => file_create_url($image_path),
'options' => array(),
);
}
$element[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $image_item,
'#image_style' => $display['settings']['imagecache_external_style'],
'#path' => isset($uri) ? $uri : '',
);
}
return $element;
}