function field_default_view

Builds a renderable array for one field on one entity instance.


$entity_type: The type of $entity; e.g. 'node' or 'user'.

$entity: A single object of type $entity_type.

$field: The field structure for the operation.

$instance: An array containing each field on $entity's bundle.

$langcode: The language associated to $items.

$items: Array of field values already loaded for the entities, keyed by entity id.

$display: Can be either:

  • the name of a view mode;
  • or an array of custom display settings, as found in the 'display' entry of $instance definitions.
2 invocations of field_default_view()
field_attach_view in modules/field/
Returns a renderable array for the fields on an entity.
field_view_field in modules/field/field.module
Returns a renderable array for the value of a single field in an entity.


modules/field/, line 191


function field_default_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
    $addition = array();
    // Prepare incoming display specifications.
    if (is_string($display)) {
        $view_mode = $display;
        $display = field_get_display($instance, $view_mode, $entity);
    else {
        $view_mode = '_custom_display';
    if ($display['type'] !== 'hidden') {
        // Calling the formatter function through module_invoke() can have a
        // performance impact on pages with many fields and values.
        $function = $display['module'] . '_field_formatter_view';
        if (function_exists($function)) {
            $elements = $function($entity_type, $entity, $field, $instance, $langcode, $items, $display);
            if ($elements) {
                $info = array(
                    '#theme' => 'field',
                    '#weight' => $display['weight'],
                    '#title' => $instance['label'],
                    '#access' => field_access('view', $field, $entity_type, $entity),
                    '#label_display' => $display['label'],
                    '#view_mode' => $view_mode,
                    '#language' => $langcode,
                    '#field_name' => $field['field_name'],
                    '#field_type' => $field['type'],
                    '#field_translatable' => $field['translatable'],
                    '#entity_type' => $entity_type,
                    '#bundle' => $bundle,
                    '#object' => $entity,
                    '#items' => $items,
                    '#formatter' => $display['type'],
                $addition[$field['field_name']] = array_merge($info, $elements);
    return $addition;

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.