You are here

function MODULE_field_diff_view_prepare in Diff 7.3

Callback to the module that defined the field to prepare items comparison.

This allows the module to alter all items prior to rendering the comparative values. It is mainly used to bulk load entities to reduce overheads associated with loading entities individually.

Parameters

array $old_items: An array of field items from the older revision.

array $new_items: An array of field items from the newer revision.

array $context: An associative array containing:

  • entity_type: The entity type; e.g., 'node' or 'user'.
  • bundle: The bundle name.
  • field: The field that the items belong to.
  • instance: The instance that the items belong to.
  • language: The language associated with $items.
  • old_entity: The older entity.
  • new_entity: The newer entity.

See also

MODULE_field_diff_view()

File

./diff.api.php, line 152
Hooks provided by the diff module.

Code

function MODULE_field_diff_view_prepare(&$old_items, &$new_items, $context) {
  $fids = array();
  foreach (array_merge_recursive($old_items, $new_items) as $info) {
    $fids[$info['fid']] = $info['fid'];
  }

  // A single load is much faster than individual loads.
  $files = file_load_multiple($fids);

  // For ease of processing, store a reference of the entity on the item array.
  foreach ($old_items as $delta => $info) {
    $old_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL;
  }
  foreach ($new_items as $delta => $info) {
    $new_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL;
  }
}