function imagefield_crop_field_formatter_view in Imagefield Crop 7.3
Implementation hook__field_formatter_view().
Parameters
$entity_type:
$entity:
$field:
$instance:
$langcode:
$items:
$display:
Return value
array|string
1 call to imagefield_crop_field_formatter_view()
- imagefield_crop_get_renderable in ./
imagefield_crop.module - Implements property callback imagefield_crop_get_renderable().
File
- ./
imagefield_crop.module, line 360
Code
function imagefield_crop_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
$entity_w = entity_metadata_wrapper($entity_type, $entity);
$key = $entity_w
->entityKey('revision') ? $entity_w
->entityKey('revision') : $entity_w
->entityKey('id');
$settings = $display['settings'];
// Check if the formatter involves a link.
if ($settings['image_link'] == 'content') {
$uri = entity_uri($entity_type, $entity);
}
elseif ($settings['image_link'] == 'file') {
$link_file = TRUE;
}
if (!empty($items[0]) && !empty($items[0]['is_default'])) {
$item = reset($items);
if (isset($link_file)) {
$uri = array(
'path' => file_create_url($item['uri']),
'options' => array(),
);
}
$element[] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $display['settings']['image_style'],
'#path' => isset($uri) ? $uri : '',
);
}
if (empty($display['settings']['preset'])) {
foreach ($items as $delta => $item) {
$presets = !empty($item['crop_config']) ? $item['crop_config'] : imagefield_crop_variants_load_multiple($item['fid'], $entity->{$key});
foreach ($presets as $pid => $preset) {
$preset = !empty($preset->data) ? $preset->data : (object) $preset;
if (!empty($preset->active) || count($presets) == 1) {
$item['uri'] = $preset->uri;
if (isset($link_file)) {
$link_url = !empty($settings['image_link_style']) ? image_style_url($settings['image_link_style'], $item['uri']) : file_create_url($item['uri']);
$uri = array(
'path' => $link_url,
'options' => array(),
);
}
$element[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $display['settings']['image_style'],
'#path' => isset($uri) ? $uri : '',
);
}
}
}
}
else {
$preset = imagefield_crop_preset_load_by_name($display['settings']['preset']);
foreach ($items as $delta => $item) {
$presets = imagefield_crop_variants_load_multiple($item['fid'], $entity->{$key}, array(
$preset->pid,
));
$preset = reset($presets);
if (!empty($preset)) {
$item['uri'] = $preset->data->uri;
if (isset($link_file)) {
$link_url = !empty($settings['image_link_style']) ? image_style_url($settings['image_link_style'], $item['uri']) : file_create_url($item['uri']);
$uri = array(
'path' => $link_url,
'options' => array(),
);
}
$element[$delta] = array(
'#theme' => 'image_formatter',
'#item' => $item,
'#image_style' => $display['settings']['image_style'],
'#path' => isset($uri) ? $uri : '',
);
}
}
}
return $element;
}