Define custom load behavior for this module's field types.
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 entity should be loaded in a single query where possible.
Note that the changes made to the field values get cached by the field cache for subsequent loads. You should never use this hook to load fieldable entities, since this is likely to cause infinite recursions when hook_field_load() is run on those as well. Use hook_field_formatter_prepare_view() instead.
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 loaded, 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 code associated with $items.
$items: Array of field values already loaded for the entities, keyed by entity ID. Store your changes in this parameter (passed by reference).
$age: FIELD_LOAD_CURRENT to load the most recent revision for all fields, or FIELD_LOAD_REVISION to load the version indicated by each entity.
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_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
// Sample code from text.module: precompute sanitized strings so they are
// stored in the field cache.
foreach ($entities as $id => $entity) {
foreach ($items[$id] as $delta => $item) {
// Only process items with a cacheable format, the rest will be handled
// by formatters if needed.
if (empty($instances[$id]['settings']['text_processing']) || filter_format_allowcache($item['format'])) {
$items[$id][$delta]['safe_value'] = isset($item['value']) ? _text_sanitize($instances[$id], $langcode, $item, 'value') : '';
if ($field['type'] == 'text_with_summary') {
$items[$id][$delta]['safe_summary'] = isset($item['summary']) ? _text_sanitize($instances[$id], $langcode, $item, 'summary') : '';
}
}
}
}
}