Prepare field values prior to display.
This hook is invoked before the field values are handed to formatters for display, and runs before the formatters' own hook_field_formatter_prepare_view().
Unlike most other field hooks, this hook operates on multiple entities. The $entities, $instances and $items parameters are arrays keyed by entity ID. For performance reasons, information for all available entities should be loaded in a single query where possible.
Make changes or additions to field values by altering the $items parameter by reference. There is no return value.
$entity_type: The type of $entity.
$entities: 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 with $items.
$items: $entity->{$field['field_name']}, or an empty array if unset.
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
function hook_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) {
// Sample code from image.module: if there are no images specified at all,
// use the default image.
foreach ($entities as $id => $entity) {
if (empty($items[$id]) && $field['settings']['default_image']) {
if ($file = file_load($field['settings']['default_image'])) {
$items[$id][0] = (array) $file + array(
'is_default' => TRUE,
'alt' => '',
'title' => '',
);
}
}
}
}