| Versionen | |
|---|---|
| drupal7 | field_view_field($obj_type, $object, $field, $instance, $teaser = FALSE) |
Return a single field, fully themed with label and multiple values.
To be used by third-party code (Views, Panels...) that needs to output an isolated field. Do *not* use inside node templates, use the $FIELD_NAME_rendered variables instead.
By default, the field is displayed using the settings defined for the 'full' or 'teaser' contexts (depending on the value of the $teaser param). Set $node->build_mode to a different value to use a different context.
Different settings can be specified by adjusting $field['display'].
$field The field definition.
$object The object containing the field to display. Must at least contain the id key, revision key (if applicable), bundle key, and the field data.
$teaser Similar to hook_node('view')
The themed output for the field.
modules/
<?php
function field_view_field($obj_type, $object, $field, $instance, $teaser = FALSE) {
$output = '';
if (isset($object->$field['field_name'])) {
$items = $object->$field['field_name'];
// Use 'full'/'teaser' if not specified otherwise.
$object->build_mode = isset($object->build_mode) ? $object->build_mode : NODE_BUILD_NORMAL;
// One-field equivalent to _field_invoke('sanitize').
$function = $field['module'] . '_field_sanitize';
if (drupal_function_exists($function)) {
$function($obj_type, $object, $field, $instance, $items);
$object->$field['field_name'] = $items;
}
$view = field_default_view($obj_type, $object, $field, $instance, $items, $teaser);
// TODO : what about hook_field_attach_view ?
// field_default_view() adds a wrapper to handle variables and 'excluded'
// fields for node templates. We bypass it and return the actual field.
$output = $view[$field['field_name']]['field'];
}
return $output;
}
?>
Kommentare
Kommentar hinzufügen