You are here

function entityreference_field_diff_view in Entity reference 7

Diff field callback for parsing entity field comparative values.

File

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

Code

function entityreference_field_diff_view($items, $context) {
  $field = $context['field'];
  $instance = $context['instance'];
  $settings = $context['settings'];
  $entity_type = $field['settings']['target_type'];
  $diff_items = array();

  // We populate as much as possible to allow the best flexability in any
  // string overrides.
  $t_args = array();
  $t_args['!entity_type'] = $entity_type;
  $entity_info = entity_get_info($entity_type);
  $t_args['!entity_type_label'] = $entity_info['label'];
  foreach ($items as $delta => $item) {
    if (isset($item['entity'])) {
      $output = array();
      list($id, , $bundle) = entity_extract_ids($entity_type, $item['entity']);
      $t_args['!id'] = $id;
      $t_args['!bundle'] = $bundle;
      $t_args['!diff_entity_label'] = entity_label($entity_type, $item['entity']);
      $output['entity'] = t('!diff_entity_label', $t_args);
      if ($settings['show_id']) {
        $output['id'] = t('ID: !id', $t_args);
      }
      $diff_items[$delta] = implode('; ', $output);
    }
  }
  return $diff_items;
}