field_attach_view
- Versions
- 7
field_attach_view($obj_type, $object, $build_mode = 'full', $langcode = NULL)
Generate and return a structured content array tree suitable for drupal_render() for all of the fields on an object. The format of each field's rendered content depends on the display formatter and its settings.
// Only for 'single-value' formatters: '#theme' => the formatter's theme function, '#formatter' => name of the formatter, '#settings' => array of formatter settings, '#object' => the fieldable object being displayed, '#object_type' => the type of the object being displayed, '#field_name' => the name of the field, '#bundle' => the object's bundle, '#delta' => 0, ), 1 => array( ... ),
// Only for 'multiple-values' formatters: '#theme' => the formatter's theme function, '#formatter' => name of the formatter, '#settings' => array of formatter settings, '#object' => the fieldable object being displayed, '#object_type' => the type of the object being displayed, '#field_name' => the name of the field, '#bundle' => the object's bundle, ), ), ); @endcode
Parameters
$obj_type The type of $object; e.g. 'node' or 'user'.
$object The object with fields to render.
$build_mode Build mode, e.g. 'full', 'teaser'...
$langcode The language the field values are to be shown in. If no language is provided the current language is used.
Return value
A structured content array tree for drupal_render(). Sample structure: @code array( 'field_foo' => array( // The structure of the array differs slightly depending on whether // the formatter is 'single-value' (displays one single field value, // most common case) or 'multiple-values' (displays all the field's // values, e.g. points on a graph or a map). '#theme' => 'field', '#title' => the label of the field instance, '#label_display' => the label display mode, '#object' => the fieldable object being displayed, '#object_type' => the type of the object being displayed, '#language' => the language of the field values being displayed, '#build_mode' => the build mode, '#field_name' => the name of the field, '#formatter_single' => boolean indicating whether the formatter is single or multiple, 'items' => array( // One sub-array per field value, keyed by delta. 0 => array( '#item' => the field value for delta 0,
Related topics
Code
modules/field/field.attach.inc, line 1181
<?php
function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode = NULL) {
// If no language is provided use the current UI language.
$options = array('language' => field_multilingual_valid_language($langcode, FALSE));
// Let field modules sanitize their data for output.
$null = NULL;
_field_invoke('sanitize', $obj_type, $object, $null, $null, $options);
$output = _field_invoke_default('view', $obj_type, $object, $build_mode, $null, $options);
// Add custom weight handling.
list($id, $vid, $bundle) = entity_extract_ids($obj_type, $object);
$output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
$output['#pre_render'][] = '_field_extra_weights_pre_render';
$output['#extra_fields'] = field_extra_fields($bundle);
// Let other modules make changes after rendering the view.
$context = array(
'obj_type' => $obj_type,
'object' => $object,
'build_mode' => $build_mode,
'langcode' => $langcode,
);
drupal_alter('field_attach_view', $output, $context);
return $output;
}
?>Login or register to post comments 