function text_field_formatter in Content Construction Kit (CCK) 6
Same name in this branch
- 6 examples/simple_field.php \text_field_formatter()
- 6 examples/example_field.php \text_field_formatter()
Same name and namespace in other branches
- 5 text.module \text_field_formatter()
Implementation of hook_field_formatter().
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().
File
- examples/
simple_field.php, line 364 - SIMPLE EXAMPLE. This is similar to to example_field but creates only a single widget formatted in the traditional manner, not using hook_elements. This example also omits all optional parts of the field module to create a simpler example for…
Code
function text_field_formatter($field, $item, $formatter, $node) {
if (!isset($item['value'])) {
return '';
}
switch ($formatter) {
case 'plain':
$text = strip_tags($item['value']);
break;
case 'default':
$text = $item['value'];
}
return check_plain($text);
}