1 field.default.inc field_default_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $display)

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 display mode
  • or an array of display settings to use for display, as found in the 'display' entry of $instance definitions.

File

core/modules/field/field.default.inc, line 143
Default 'implementations' of hook_field_*(): common field housekeeping.

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]);
    }
  }
}