field_attach_view($entity_type, $entity, $view_mode = 'full', $langcode = NULL)Returns a renderable array for the fields on an entity.
Each field is displayed according to the display options specified in the $instance definition for the given $view_mode.
The entity must have run through field_attach_prepare_view() beforehands.
Sample structure:
<?php
array(
'field_foo' => array(
'#theme' => 'field',
'#title' => the label of the field instance,
'#label_display' => the label display mode,
'#object' => the fieldable entity being displayed,
'#object_type' => the type of the entity being displayed,
'#language' => the language of the field values being displayed,
'#view_mode' => the view mode,
'#field_name' => the name of the field,
'#field_type' => the type of the field,
'#formatter' => the name of the formatter,
'#items' => the field values being displayed,
// The element's children are the formatted values returned by
// hook_field_formatter_view().
),
);
?>
$entity_type The type of $entity; e.g. 'node' or 'user'.
$entity The entity with fields to render.
$view_mode View 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.
A renderable array for the field values.
modules/field/field.attach.inc, line 1201
<?php
function field_attach_view($entity_type, $entity, $view_mode = 'full', $langcode = NULL) {
// Invoke field_default_view(). If no language is provided, use the current
// UI language.
$options = array('language' => field_multilingual_valid_language($langcode, FALSE));
$null = NULL;
$output = _field_invoke_default('view', $entity_type, $entity, $view_mode, $null, $options);
// Add custom weight handling.
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$output['#pre_render'][] = '_field_extra_weights_pre_render';
$output['#extra_fields'] = field_extra_fields($entity_type, $bundle);
// Include CSS styles.
$output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
// Let other modules alter the renderable array.
$context = array(
'obj_type' => $entity_type,
'object' => $entity,
'view_mode' => $view_mode,
'langcode' => $langcode,
);
drupal_alter('field_attach_view', $output, $context);
// Reset the _field_view_prepared flag set in field_attach_prepare_view(),
// in case the same entity is displayed with different settings later in
// the request.
unset($entity->_field_view_prepared);
return $output;
}
?>