Projet

Général

Profil

Révision 661d64c9

Ajouté par Assos Assos il y a plus de 7 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/diff/diff.api.php
11 11
 */
12 12

  
13 13
/**
14
 * Allow modules to provide a comparison about entities.
14
 * Allow modules to provide a comparison about entity properties.
15 15
 *
16 16
 * @param object $old_entity
17 17
 *   The older entity revision.
18
 *
18 19
 * @param object $new_entity
19 20
 *   The newer entity revision.
21
 *
20 22
 * @param array $context
21 23
 *   An associative array containing:
22 24
 *   - entity_type: The entity type; e.g., 'node' or 'user'.
23
 *   - view_mode: The view mode to use. Defaults to FALSE.
25
 *   - old_entity: The older entity.
26
 *   - new_entity: The newer entity.
27
 *   - view_mode: The view mode to use. Defaults to FALSE. If no view mode is
28
 *                given, the recommended fallback view mode is 'default'.
29
 *   - states: An array of view states. These could be one of:
30
 *     - raw: The raw value of the diff, the classic 7.x-2.x view.
31
 *     - rendered: The rendered HTML as determined by the view mode. Only
32
 *                 return markup for this state if the value is normally shown
33
 *                 by this view mode. The user will most likely be able to see
34
 *                 the raw or raw_plain state, so this is optional.
35
 *
36
 *                 The rendering state is a work in progress.
37
 *
38
 *     Conditionally, you can get these states, but setting these will override
39
 *     the user selectable markdown method.
40
 *
41
 *     - raw_plain: As raw, but text should be markdowned.
42
 *     - rendered_plain: As rendered, but text should be markdowned.
24 43
 *
25 44
 * @return array
26 45
 *   An associative array of values keyed by the entity property.
27 46
 *
28
 * @todo
29
 *   Investiagate options and document these.
47
 *   This is effectively an unnested Form API-like structure.
48
 *
49
 *   States are returned as follows:
50
 *
51
 *   $results['line'] = array(
52
 *     '#name' => t('Line'),
53
 *     '#states' => array(
54
 *       'raw' => array(
55
 *         '#old' => '<p class="line">This was the old line number [tag].</p>',
56
 *         '#new' => '<p class="line">This is the new line [tag].</p>',
57
 *       ),
58
 *       'rendered' => array(
59
 *         '#old' => '<p class="line">This was the old line number <span class="line-number">57</span>.</p>',
60
 *         '#new' => '<p class="line">This is the new line <span class="line-number">57</span>.</p>',
61
 *       ),
62
 *     ),
63
 *   );
64
 *
65
 *   For backwards compatibility, no changes are required to support states,
66
 *   but it is recommended to provide a better UI for end users.
67
 *
68
 *   For example, the following example is equivalent to returning the raw
69
 *   state from the example above.
70
 *
71
 *   $results['line'] = array(
72
 *     '#name' => t('Line'),
73
 *     '#old' => '<p class="line">This was the old line number [tag].</p>',
74
 *     '#new' => '<p class="line">This is the new line [tag].</p>',
75
 *   );
30 76
 */
31 77
function hook_entity_diff($old_entity, $new_entity, $context) {
78
  $results = array();
79

  
32 80
  if ($context['entity_type'] == 'node') {
33 81
    $type = node_type_get_type($new_entity);
34
    $result['title'] = array(
82
    $results['title'] = array(
35 83
      '#name' => $type->title_label,
36 84
      '#old' => array($old_entity->title),
37 85
      '#new' => array($new_entity->title),
......
41 89
      ),
42 90
    );
43 91
  }
92

  
93
  return $results;
44 94
}
45 95

  
46 96
/**
......
57 107
 *
58 108
 * @see hook_entity_diff()
59 109
 */
60
function hook_entity_diff_alter($entity_diffs, $context) {
110
function hook_entity_diff_alter(&$entity_diffs, $context) {
61 111
}
62 112

  
63 113
/**

Formats disponibles : Unified diff