function field_default_prepare_view

Invokes hook_field_formatter_prepare_view() on the relevant formatters.

Parameters

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

$entities: An array of entities being displayed, keyed by entity id.

$field: The field structure for the operation.

$instances: Array of instance structures for $field for each entity, keyed by entity id.

$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 display settings to use for display, as found in the 'display' entry of $instance definitions.
2 invocations of field_default_prepare_view()
field_attach_prepare_view in modules/field/field.attach.inc
Prepare field data prior to display.
field_view_field in modules/field/field.module
Returns a renderable array for the value of a single field in an entity.

File

modules/field/field.default.inc, line 138

Code

function field_default_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $display) {
    // Group entities, instances and items by formatter module.
    $modules = array();
    foreach ($instances as $id => $instance) {
        if (is_string($display)) {
            $view_mode = $display;
            $instance_display = field_get_display($instance, $view_mode, $entities[$id]);
        }
        else {
            $instance_display = $display;
        }
        if ($instance_display['type'] !== 'hidden') {
            $module = $instance_display['module'];
            $modules[$module] = $module;
            $grouped_entities[$module][$id] = $entities[$id];
            $grouped_instances[$module][$id] = $instance;
            $grouped_displays[$module][$id] = $instance_display;
            // hook_field_formatter_prepare_view() alters $items by reference.
            $grouped_items[$module][$id] =& $items[$id];
        }
    }
    foreach ($modules as $module) {
        // Invoke hook_field_formatter_prepare_view().
        $function = $module . '_field_formatter_prepare_view';
        if (function_exists($function)) {
            $function($entity_type, $grouped_entities[$module], $field, $grouped_instances[$module], $langcode, $grouped_items[$module], $grouped_displays[$module]);
        }
    }
}

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