function hook_field_formatter in Content Construction Kit (CCK) 5
Prepare an individual item for viewing in a browser.
Parameters
$field: The field the action is being performed on.
$item: An array, keyed by column, of the data stored for this item in this field.
$formatter: The name of the formatter being used to display the field.
$node: The node object, for context. Will be NULL in some cases. Warning : when displaying field retrieved by Views, $node will not be a "full-fledged" node object, but an object containg the data returned by the Views query (at least nid, vid, changed)
Return value
An HTML string containing the formatted item.
In a multiple-value field scenario, this function will be called once per value currently stored in the field. This function is also used as the handler for viewing a field in a views.module tabular listing.
It is important that this function at the minimum perform security transformations such as running check_plain() or check_markup().
4 functions implement hook_field_formatter()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- nodereference_field_formatter in ./
nodereference.module - Implementation of hook_field_formatter().
- number_field_formatter in ./
number.module - Implementation of hook_field_formatter().
- text_field_formatter in ./
text.module - Implementation of hook_field_formatter().
- userreference_field_formatter in ./
userreference.module - Implementation of hook_field_formatter().
1 invocation of hook_field_formatter()
- content_format in ./
content.module - Format a field item for display.
File
- ./
field.php, line 279 - These hooks are defined by field modules, modules that define a new kind of field for insertion in a content type.
Code
function hook_field_formatter($field, $item, $formatter, $node) {
if (!isset($item['value'])) {
return '';
}
if ($field['text_processing']) {
$text = check_markup($item['value'], $item['format'], is_null($node) || isset($node->in_preview));
}
else {
$text = check_plain($item['value']);
}
switch ($formatter) {
case 'plain':
return strip_tags($text);
case 'trimmed':
return node_teaser($text, $field['text_processing'] ? $item['format'] : NULL);
default:
return $text;
}
}