function thickbox_field_formatter in Thickbox 6
Same name and namespace in other branches
- 5 thickbox.module \thickbox_field_formatter()
Implementation of hook_field_formatter().
1 call to thickbox_field_formatter()
File
- ./
thickbox.module, line 176 - Author: Fredrik Jonsson fredrik at combonet dot se The thickbox module is a simple wrapper for the jquery plugin ThickBox http://jquery.com/demo/thickbox/.
Code
function thickbox_field_formatter($field, $item, $formatter, $node) {
if (module_exists('imagefield') && module_exists('imagecache') && !empty($item['fid'])) {
if (is_string($item['data'])) {
$item['data'] = unserialize($item['data']);
}
if (!isset($item['filepath'])) {
$file = field_file_load($item['fid']);
$item['filepath'] = $file['filepath'];
}
// If the title is empty use description, alt or the node title in that order.
if (empty($item['data']['title'])) {
if (!empty($item['data']['description'])) {
$item['data']['title'] = $item['data']['description'];
}
else {
if (!empty($item['data']['alt'])) {
$item['data']['title'] = $item['data']['alt'];
}
else {
$item['data']['title'] = $node->title;
}
}
}
// Build the gallery id.
$nid = $item['nid'] ? $item['nid'] : ($node->nid ? $node->nid : '');
switch (variable_get('thickbox_imagefield_gallery', 1)) {
case 0:
$gallery_id = 'all';
break;
case 1:
$gallery_id = $nid;
break;
case 2:
$gallery_id = $nid . '-' . $field;
break;
case 3:
$gallery_id = $nid . '-' . $item['fid'];
break;
}
list($namespace, $presetname) = explode('][', $formatter, 2);
if ($preset = imagecache_preset_by_name($namespace)) {
return theme('imagefield_image_imagecache_thickbox', $namespace, $item['filepath'], $item['data']['alt'], $item['data']['title'], $gallery_id);
}
}
}