Mercurial > hg > rr-repo
comparison sites/all/modules/entityreference/entityreference.diff.inc @ 4:ce11bbd8f642
added modules
author | danieleb <danielebarchiesi@me.com> |
---|---|
date | Thu, 19 Sep 2013 10:38:44 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:b28be78d8160 | 4:ce11bbd8f642 |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * @file | |
5 * Provide Diff module field callbacks for the Entity Reference module. | |
6 */ | |
7 | |
8 /** | |
9 * Diff field callback for preloading entities. | |
10 */ | |
11 function entityreference_field_diff_view_prepare(&$old_items, &$new_items, $context) { | |
12 $field = $context['field']; | |
13 | |
14 // Build an array of entities ID. | |
15 $entity_ids = array(); | |
16 foreach (array_merge_recursive($old_items, $new_items) as $item) { | |
17 $entity_ids[] = $item['target_id']; | |
18 } | |
19 | |
20 // Load those entities and loop through them to extract their labels. | |
21 $entities = entity_load($field['settings']['target_type'], $entity_ids); | |
22 | |
23 foreach ($old_items as $delta => $info) { | |
24 $old_items[$delta]['entity'] = isset($entities[$info['target_id']]) ? $entities[$info['target_id']] : NULL; | |
25 } | |
26 foreach ($new_items as $delta => $info) { | |
27 $new_items[$delta]['entity'] = isset($entities[$info['target_id']]) ? $entities[$info['target_id']] : NULL; | |
28 } | |
29 } | |
30 | |
31 /** | |
32 * Diff field callback for parsing entity field comparative values. | |
33 */ | |
34 function entityreference_field_diff_view($items, $context) { | |
35 $field = $context['field']; | |
36 $instance = $context['instance']; | |
37 $settings = $context['settings']; | |
38 $entity_type = $field['settings']['target_type']; | |
39 | |
40 $diff_items = array(); | |
41 | |
42 // We populate as much as possible to allow the best flexability in any | |
43 // string overrides. | |
44 $t_args = array(); | |
45 $t_args['!entity_type'] = $entity_type; | |
46 | |
47 $entity_info = entity_get_info($entity_type); | |
48 $t_args['!entity_type_label'] = $entity_info['label']; | |
49 | |
50 foreach ($items as $delta => $item) { | |
51 if (isset($item['entity'])) { | |
52 $output = array(); | |
53 | |
54 list($id,, $bundle) = entity_extract_ids($entity_type, $item['entity']); | |
55 $t_args['!id'] = $id; | |
56 $t_args['!bundle'] = $bundle; | |
57 $t_args['!diff_entity_label'] = entity_label($entity_type, $item['entity']); | |
58 | |
59 $output['entity'] = t('!diff_entity_label', $t_args); | |
60 if ($settings['show_id']) { | |
61 $output['id'] = t('ID: !id', $t_args); | |
62 } | |
63 $diff_items[$delta] = implode('; ', $output); | |
64 } | |
65 } | |
66 | |
67 return $diff_items; | |
68 } | |
69 | |
70 /** | |
71 * Provide default field comparison options. | |
72 */ | |
73 function entityreference_field_diff_default_options($field_type) { | |
74 return array( | |
75 'show_id' => 0, | |
76 ); | |
77 } | |
78 | |
79 /** | |
80 * Provide a form for setting the field comparison options. | |
81 */ | |
82 function entityreference_field_diff_options_form($field_type, $settings) { | |
83 $options_form = array(); | |
84 $options_form['show_id'] = array( | |
85 '#type' => 'checkbox', | |
86 '#title' => t('Show ID'), | |
87 '#default_value' => $settings['show_id'], | |
88 ); | |
89 return $options_form; | |
90 } |