hook_field_load

Versions
7
hook_field_load($obj_type, $objects, $field, $instances, $langcode, &$items, $age)

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. 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.

Parameters

$obj_type The type of $object.

$objects Array of objects being loaded, keyed by object id.

$field The field structure for the operation.

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

$langcode The language associated to $items.

$items Array of field values already loaded for the objects, keyed by object id.

$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 value

Changes or additions to field values are done by altering the $items parameter by reference.

Related topics

Code

modules/field/field.api.php, line 275

<?php
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) : '';
          if ($field['type'] == 'text_with_summary') {
            $items[$id][$delta]['safe_summary'] = isset($item['summary']) ? check_markup($item['summary'], $format, $langcode) : '';
          }
        }
      }
      else {
        $items[$id][$delta]['safe'] = check_plain($item['value']);
        if ($field['type'] == 'text_with_summary') {
          $items[$id][$delta]['safe_summary'] = check_plain($item['summary']);
        }
      }
    }
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.