field_attach_view

Versions
mediamosa-21
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.

See also

field_attach_prepare_view()

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().
  ),
);

?>

Parameters

$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.

Return value

A renderable array for the field values.

Related topics

▾ 6 functions call field_attach_view()

comment_build_content in modules/comment/comment.module
Builds a structured array representing the comment's content.
devel_render_term in sites/all/modules/devel/devel.module
Menu callback; prints the render structure of the a term.
locale_field_fallback_view in modules/locale/locale.field.inc
Apply fallback rules to the given object.
node_build_content in modules/node/node.module
Builds a structured array representing the node's content.
taxonomy_term_view in modules/taxonomy/taxonomy.module
Generate an array for rendering the given term.
user_build_content in modules/user/user.module
Builds a structured array representing the profile content.

Code

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;
}
?>