1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Provide diff functions for the node module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Implements hook_entity_diff().
|
10 |
|
|
*
|
11 |
|
|
* This function compares core node properties. This is currently limited to:
|
12 |
|
|
* - title: The title of the node.
|
13 |
|
|
*
|
14 |
|
|
* @param object $old_node
|
15 |
|
|
* The older node revision.
|
16 |
|
|
* @param object $new_node
|
17 |
|
|
* The newer node revision.
|
18 |
|
|
* @param array $context
|
19 |
|
|
* An associative array containing:
|
20 |
|
|
* - entity_type: The entity type; e.g., 'node' or 'user'.
|
21 |
|
|
* - old_entity: The older entity.
|
22 |
|
|
* - new_entity: The newer entity.
|
23 |
|
|
* - view_mode: The view mode to use. Defaults to FALSE. If no view mode is
|
24 |
|
|
* given, the recommended fallback view mode is 'default'.
|
25 |
|
|
* - states: An array of view states. These could be one of:
|
26 |
|
|
* - raw: The raw value of the diff, the classic 7.x-2.x view.
|
27 |
|
|
* - rendered: The rendered HTML as determined by the view mode. Only
|
28 |
|
|
* return markup for this state if the value is normally shown
|
29 |
|
|
* by this view mode. The user will most likely be able to see
|
30 |
|
|
* the raw or raw_plain state, so this is optional.
|
31 |
|
|
*
|
32 |
|
|
* The rendering state is a work in progress.
|
33 |
|
|
*
|
34 |
|
|
* Conditionally, you can get these states, but setting these will override
|
35 |
|
|
* the user selectable markdown method.
|
36 |
|
|
*
|
37 |
|
|
* - raw_plain: As raw, but text should be markdowned.
|
38 |
|
|
* - rendered_plain: As rendered, but text should be markdowned.
|
39 |
|
|
*
|
40 |
|
|
* @return array
|
41 |
|
|
* An associative array of values keyed by the entity property.
|
42 |
|
|
*
|
43 |
|
|
* This is effectively an unnested Form API-like structure.
|
44 |
|
|
*
|
45 |
|
|
* States are returned as follows:
|
46 |
|
|
*
|
47 |
|
|
* $results['line'] = array(
|
48 |
|
|
* '#name' => t('Line'),
|
49 |
|
|
* '#states' => array(
|
50 |
|
|
* 'raw' => array(
|
51 |
|
|
* '#old' => '<p class="line">This was the old line number [tag].</p>',
|
52 |
|
|
* '#new' => '<p class="line">This is the new line [tag].</p>',
|
53 |
|
|
* ),
|
54 |
|
|
* 'rendered' => array(
|
55 |
|
|
* '#old' => '<p class="line">This was the old line number <span class="line-number">57</span>.</p>',
|
56 |
|
|
* '#new' => '<p class="line">This is the new line <span class="line-number">57</span>.</p>',
|
57 |
|
|
* ),
|
58 |
|
|
* ),
|
59 |
|
|
* );
|
60 |
|
|
*
|
61 |
|
|
* For backwards compatability, no changes are required to support states,
|
62 |
|
|
* but it is recommended to provide a better UI for end users.
|
63 |
|
|
*
|
64 |
|
|
* For example, the following example is equivalent to returning the raw
|
65 |
|
|
* state from the example above.
|
66 |
|
|
*
|
67 |
|
|
* $results['line'] = array(
|
68 |
|
|
* '#name' => t('Line'),
|
69 |
|
|
* '#old' => '<p class="line">This was the old line number [tag].</p>',
|
70 |
|
|
* '#new' => '<p class="line">This is the new line [tag].</p>',
|
71 |
|
|
* );
|
72 |
|
|
*/
|
73 |
|
|
function node_entity_diff($old_node, $new_node, $context) {
|
74 |
|
|
$result = array();
|
75 |
|
|
if ($context['entity_type'] == 'node') {
|
76 |
|
|
$type = node_type_get_type($new_node);
|
77 |
|
|
$result['title'] = array(
|
78 |
|
|
'#name' => $type->title_label,
|
79 |
|
|
'#states' => array(),
|
80 |
|
|
'#weight' => -5,
|
81 |
|
|
'#settings' => array(
|
82 |
|
|
// Global setting - 'diff_show_header_' . $entity_type
|
83 |
|
|
'show_header' => variable_get('diff_show_header_node', 1),
|
84 |
|
|
),
|
85 |
|
|
);
|
86 |
|
|
foreach ($context['states'] as $state) {
|
87 |
|
|
switch ($state) {
|
88 |
|
|
case 'rendered':
|
89 |
|
|
$result['title']['#states'][$state] = array(
|
90 |
|
|
'#old' => l($old_node->title, 'node/' . $old_node->title),
|
91 |
|
|
'#new' => l($new_node->title, 'node/' . $new_node->title),
|
92 |
|
|
);
|
93 |
|
|
break;
|
94 |
|
|
|
95 |
|
|
// We specify a default so that the title is allows compared.
|
96 |
|
|
case 'raw':
|
97 |
|
|
default:
|
98 |
|
|
$result['title']['#states'][$state] = array(
|
99 |
|
|
'#old' => array($old_node->title),
|
100 |
|
|
'#new' => array($new_node->title),
|
101 |
|
|
);
|
102 |
|
|
break;
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
|
|
return $result;
|
107 |
|
|
} |