root / drupal7 / sites / all / modules / diff / diff.api.php @ f4462ddf
1 | 85ad3d82 | Assos Assos | <?php
|
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * @file
|
||
5 | * Hooks provided by the diff module.
|
||
6 | */
|
||
7 | |||
8 | /**
|
||
9 | * @addtogroup hooks
|
||
10 | * @{
|
||
11 | */
|
||
12 | |||
13 | /**
|
||
14 | * Allow modules to provide a comparison about entities.
|
||
15 | *
|
||
16 | * @param object $old_entity
|
||
17 | * The older entity revision.
|
||
18 | * @param object $new_entity
|
||
19 | * The newer entity revision.
|
||
20 | * @param array $context
|
||
21 | * An associative array containing:
|
||
22 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
23 | * - view_mode: The view mode to use. Defaults to FALSE.
|
||
24 | *
|
||
25 | * @return array
|
||
26 | * An associative array of values keyed by the entity property.
|
||
27 | *
|
||
28 | * @todo
|
||
29 | * Investiagate options and document these.
|
||
30 | */
|
||
31 | function hook_entity_diff($old_entity, $new_entity, $context) { |
||
32 | if ($context['entity_type'] == 'node') { |
||
33 | $type = node_type_get_type($new_entity); |
||
34 | $result['title'] = array( |
||
35 | '#name' => $type->title_label, |
||
36 | '#old' => array($old_entity->title), |
||
37 | '#new' => array($new_entity->title), |
||
38 | '#weight' => -5, |
||
39 | '#settings' => array( |
||
40 | 'show_header' => FALSE, |
||
41 | ), |
||
42 | ); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | /**
|
||
47 | * Allow modules to alter a comparison about entities.
|
||
48 | *
|
||
49 | * @param array $entity_diffs
|
||
50 | * An array of entity differences.
|
||
51 | * @param array $context
|
||
52 | * An associative array containing:
|
||
53 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
54 | * - old_entity: The older entity.
|
||
55 | * - new_entity: The newer entity.
|
||
56 | * - view_mode: The view mode to use. Defaults to FALSE.
|
||
57 | *
|
||
58 | * @see hook_entity_diff()
|
||
59 | */
|
||
60 | function hook_entity_diff_alter($entity_diffs, $context) { |
||
61 | } |
||
62 | |||
63 | /**
|
||
64 | * Callback to the module that defined the field to prepare items comparison.
|
||
65 | *
|
||
66 | * This allows the module to alter all items prior to rendering the comparative
|
||
67 | * values. It is mainly used to bulk load entities to reduce overheads
|
||
68 | * associated with loading entities individually.
|
||
69 | *
|
||
70 | * @param array $old_items
|
||
71 | * An array of field items from the older revision.
|
||
72 | * @param array $new_items
|
||
73 | * An array of field items from the newer revision.
|
||
74 | * @param array $context
|
||
75 | * An associative array containing:
|
||
76 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
77 | * - bundle: The bundle name.
|
||
78 | * - field: The field that the items belong to.
|
||
79 | * - instance: The instance that the items belong to.
|
||
80 | * - language: The language associated with $items.
|
||
81 | * - old_entity: The older entity.
|
||
82 | * - new_entity: The newer entity.
|
||
83 | *
|
||
84 | * @see MODULE_field_diff_view()
|
||
85 | */
|
||
86 | function MODULE_field_diff_view_prepare(&$old_items, &$new_items, $context) { |
||
87 | $fids = array(); |
||
88 | foreach (array_merge_recursive($old_items, $new_items) as $info) { |
||
89 | $fids[$info['fid']] = $info['fid']; |
||
90 | } |
||
91 | // A single load is much faster than individual loads.
|
||
92 | $files = file_load_multiple($fids); |
||
93 | |||
94 | // For ease of processing, store a reference of the entity on the item array.
|
||
95 | foreach ($old_items as $delta => $info) { |
||
96 | $old_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL; |
||
97 | } |
||
98 | foreach ($new_items as $delta => $info) { |
||
99 | $new_items[$delta]['file'] = isset($files[$info['fid']]) ? $files[$info['fid']] : NULL; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | /**
|
||
104 | * Callback to the module that defined the field to generate items comparisons.
|
||
105 | *
|
||
106 | * @param array $items
|
||
107 | * An array of field items from the entity.
|
||
108 | * @param array $context
|
||
109 | * An associative array containing:
|
||
110 | * - entity: The entity being compared.
|
||
111 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
112 | * - bundle: The bundle name.
|
||
113 | * - field: The field that the items belong to.
|
||
114 | * - instance: The instance that the items belong to.
|
||
115 | * - language: The language associated with $items.
|
||
116 | * - old_entity: The older entity.
|
||
117 | * - new_entity: The newer entity.
|
||
118 | *
|
||
119 | * @see MODULE_field_diff_view_prepare()
|
||
120 | */
|
||
121 | function MODULE_field_diff_view($items, $context) { |
||
122 | $diff_items = array(); |
||
123 | foreach ($items as $delta => $item) { |
||
124 | if (isset($item['file'])) { |
||
125 | $diff_items[$delta] = $item['file']->filename . ' [fid: ' . $item['fid'] . ']'; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | return $diff_items; |
||
130 | } |
||
131 | |||
132 | /**
|
||
133 | * Allow other modules to interact with MODULE_field_diff_view_prepare().
|
||
134 | *
|
||
135 | * @param array $old_items
|
||
136 | * An array of field items from the older revision.
|
||
137 | * @param array $new_items
|
||
138 | * An array of field items from the newer revision.
|
||
139 | * @param array $context
|
||
140 | * An associative array containing:
|
||
141 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
142 | * - bundle: The bundle name.
|
||
143 | * - field: The field that the items belong to.
|
||
144 | * - instance: The instance that the items belong to.
|
||
145 | * - language: The language associated with $items.
|
||
146 | * - old_entity: The older entity.
|
||
147 | * - new_entity: The newer entity.
|
||
148 | *
|
||
149 | * @see MODULE_field_diff_view_prepare()
|
||
150 | */
|
||
151 | function hook_field_diff_view_prepare_alter($old_items, $new_items, $context) { |
||
152 | |||
153 | } |
||
154 | |||
155 | /**
|
||
156 | * Allow other modules to interact with MODULE_field_diff_view().
|
||
157 | *
|
||
158 | * @param array $values
|
||
159 | * An array of field items from the entity ready for comparison.
|
||
160 | * @param array $items
|
||
161 | * An array of field items from the entity.
|
||
162 | * @param array $context
|
||
163 | * An associative array containing:
|
||
164 | * - entity: The entity being compared.
|
||
165 | * - entity_type: The entity type; e.g., 'node' or 'user'.
|
||
166 | * - bundle: The bundle name.
|
||
167 | * - field: The field that the items belong to.
|
||
168 | * - instance: The instance that the items belong to.
|
||
169 | * - language: The language associated with $items.
|
||
170 | * - old_entity: The older entity.
|
||
171 | * - new_entity: The newer entity.
|
||
172 | *
|
||
173 | * @see MODULE_field_diff_view()
|
||
174 | */
|
||
175 | function hook_field_diff_view_alter($values, $items, $context) { |
||
176 | |||
177 | } |
||
178 | |||
179 | /**
|
||
180 | * @} End of "addtogroup hooks".
|
||
181 | */ |