hook_field_formatter($field, $item, $formatter, $node)
cck.pre-rename/field.php, line 279
Prepare an individual item for viewing in a browser.
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().
$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)
An HTML string containing the formatted item.
| Name | Description |
|---|---|
| Hooks | Allow modules to interact with the Drupal core. |
<?php
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;
}
}
?>