<?php
// $Id$
/**
* Stole this code from image cache, goal here is to add one more
* formatter that links to node/nid/large instead of node/nid
* and shows up in the list on Home » Administer » Content management » Content types » Display fields
*/
/**
* Implementation of hook_field_formatter_info().
* Adds image linked to large view display option.
*/
function largeview_field_formatter_info() {
foreach (imagecache_presets() as $preset) {
$formatters[$preset['presetname'] .
'_linkedlarge'] =
array(
'label' =>
t('@preset image linked to node large',
array('@preset' =>
$preset['presetname'])),
'field types' =>
array('image',
'filefield'),
);
}
return $formatters;
}
/**
* Implementation of hook_field_formatter().
*/
function largeview_field_formatter($field, $item, $formatter, $node) {
if (empty($item['fid']) &&
$field['use_default_image']) {
$item = $field['default_image'];
}
// Views does not load the file for us, while CCK display fields does.
if (empty($item['filepath'])) {
$item =
array_merge($item, field_file_load
($item['fid']));
}
$alt =
empty($item['data']['alt']) ?
'' :
$item['data']['alt'];
$title =
empty($item['data']['title']) ?
'' :
$item['data']['title'];
$presetname =
implode('_',
$parts);
$class = "imagecache imagecache-$presetname imagecache-$style imagecache-$formatter";
if ($preset = imagecache_preset_by_name($presetname)) {
$item['filepath'] = $item['fid'] == 'upload' ? $item['preview'] : $item['filepath'];
switch ($style) {
case 'linkedlarge':
$imagetag =
theme('largeview',
$presetname,
$item['filepath'],
$alt,
$title);
return l($imagetag,
'node/'.
$node->
nid .
'/large',
array('attributes' =>
array('class' =>
$class),
'html' =>
true));
default:
return theme('largeview',
$presetname,
$item['filepath'],
$item['data']['alt'],
$item['data']['title']);
}
}
return '<!-- imagecache formatter preset('. $presetname .') not found! -->';
}
function theme_largeview_formatter($element) {
if (isset($element['#item']['nid']) &&
$node =
node_load($element['#item']['nid'])) {
return imagecache_field_formatter($element['#field_name'], $element['#item'], $element['#formatter'], $node);
}
}