You are here

function entityreference_field_diff_view_prepare in Entity reference 7

Diff field callback for preloading entities.

File

./entityreference.diff.inc, line 11
Provide Diff module field callbacks for the Entity Reference module.

Code

function entityreference_field_diff_view_prepare(&$old_items, &$new_items, $context) {
  $field = $context['field'];

  // Build an array of entities ID.
  $entity_ids = array();
  foreach (array_merge_recursive($old_items, $new_items) as $item) {
    $entity_ids[] = $item['target_id'];
  }

  // Load those entities and loop through them to extract their labels.
  $entities = entity_load($field['settings']['target_type'], $entity_ids);
  foreach ($old_items as $delta => $info) {
    $old_items[$delta]['entity'] = isset($entities[$info['target_id']]) ? $entities[$info['target_id']] : NULL;
  }
  foreach ($new_items as $delta => $info) {
    $new_items[$delta]['entity'] = isset($entities[$info['target_id']]) ? $entities[$info['target_id']] : NULL;
  }
}