/** * Define custom load behavior for this module's field types. * * Unlike other field hooks, this hook operates on multiple objects. The * $objects, $instances and $items parameters are arrays keyed by object id. * For performance reasons, information for all available objects 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. * * @param $obj_type * The type of $object. * @param $objects * Array of objects being loaded, keyed by object id. * @param $field * The field structure for the operation. * @param $instances * Array of instance structures for $field for each object, keyed by object id. * @param $langcode * The language associated to $items. * @param $items * Array of field values already loaded for the objects, keyed by object id. * @param $age * FIELD_LOAD_CURRENT to load the most recent revision for all fields, or * FIELD_LOAD_REVISION to load the version indicated by each object. * @return * Changes or additions to field values are done by altering the $items * parameter by reference. */ function hook_field_load($obj_type, $objects, $field, $instances, $langcode, &$items, $age) { foreach ($objects as $id => $object) { foreach ($items[$id] as $delta => $item) { if (!empty($instances[$id]['settings']['text_processing'])) { // Only process items with a cacheable format, the rest will be // handled by hook_field_sanitize(). $format = $item['format']; if (filter_format_allowcache($format)) { $items[$id][$delta]['safe'] = isset($item['value']) ? check_markup($item['value'], $format, $langcode, FALSE) : ''; if ($field['type'] == 'text_with_summary') { $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode, FALSE) : ''; } } } else { $items[$id][$delta]['safe'] = check_plain($item['value']); if ($field['type'] == 'text_with_summary') { $items[$id][$delta]['safe_summary'] = check_plain($item['summary']); } } } } }
/** * 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. * * @param $entity_type * The type of $entity. * @param $entities * Array of entities being loaded, keyed by entity ID. * @param $field * The field structure for the operation. * @param $instances * Array of instance structures for $field for each entity, keyed by entity * ID. * @param $langcode * The language code associated with $items. * @param $items * Array of field values already loaded for the entities, keyed by entity ID. * Store your changes in this parameter (passed by reference). * @param $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. */ 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') : ''; } } } } }