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.diff.inc
12 12
 *
13 13
 * This manually invokes hook_diff() to avoid a function name clash with the
14 14
 * PHP 5 (>= 5.3.0) date_diff() function or the Dates modules implementation.
15
 *
16
 * @param object $old_entity
17
 *   The older node revision.
18
 * @param object $new_entity
19
 *   The newer node revision.
20
 * @param array $context
21
 *   An associative array containing:
22
 *   - entity_type: The entity type; e.g., 'node' or 'user'.
23
 *   - old_entity: The older entity.
24
 *   - new_entity: The newer entity.
25
 *   - view_mode: The view mode to use. Defaults to FALSE.
26 15
 */
27 16
function diff_entity_diff($old_entity, $new_entity, $context) {
28 17
  $return = array();
......
52 41
 *   - old_entity: The older entity.
53 42
 *   - new_entity: The newer entity.
54 43
 *   - view_mode: The view mode to use. Defaults to FALSE.
44
 * @param string $default_langcode
45
 *   (optional) Language code to force comparison in.
55 46
 *
56 47
 * @return array
57 48
 *   An associative array of values keyed by the field name and delta value.
58 49
 */
59
function diff_entity_fields_diff($old_entity, $new_entity, $context) {
50
function diff_entity_fields_diff($old_entity, $new_entity, $context, $default_langcode = NULL) {
60 51
  $result = array();
61 52

  
62 53
  $entity_type = $context['entity_type'];
......
65 56
  $field_context = $context;
66 57

  
67 58
  $actual_mode = FALSE;
68
  list(,, $bundle_name) = entity_extract_ids($entity_type, $new_entity);
59
  list(, , $bundle_name) = entity_extract_ids($entity_type, $new_entity);
69 60
  $instances = field_info_instances($entity_type, $bundle_name);
70 61

  
71 62
  // Some fields piggy back the display settings, so we need to fake these by
......
98 89

  
99 90
    // We provide a loose check on the field access.
100 91
    if (field_access('view', $field, $entity_type) || field_access('edit', $field, $entity_type)) {
101
      $langcode = field_language($entity_type, $new_entity, $field_name);
92
      $langcode = $default_langcode ? $default_langcode : field_language($entity_type, $new_entity, $field_name);
102 93

  
103 94
      $field_context['language'] = $langcode;
104 95
      $field_context['field'] = $field;
......
136 127
        $func = 'diff_field_diff_view';
137 128
      }
138 129

  
130
      // Copy the static ID cache to ensure this is the same for each comparison.
131
      $original_html_ids = drupal_static('drupal_html_id');
132
      $html_ids = &drupal_static('drupal_html_id');
133

  
139 134
      // These callbacks should be independent of revision.
140 135
      $old_context = $field_context;
141 136
      $old_context['entity'] = $old_entity;
142 137
      $old_values = $func($old_items, $old_context);
138

  
139
      // Restores the ID cache to the original.
140
      $html_ids = $original_html_ids;
141

  
143 142
      $new_context = $field_context;
144 143
      $new_context['entity'] = $new_entity;
145 144
      $new_values = $func($new_items, $new_context);
......
200 199
 *   An array of strings representing the value, keyed by delta index.
201 200
 */
202 201
function diff_field_diff_view($items, $context) {
202
  // Prevent unnecessary rendering of the field. This also prevents issues
203
  // where field_view_field() will use a language fallback for display that
204
  // may not match the requested diff comparison language.
205
  if (!$items) {
206
    return array();
207
  }
208

  
203 209
  $diff_items = array();
204
   $entity = clone $context['entity'];
205
   $langcode = field_language($context['entity_type'], $entity, $context['field']['field_name']);
206
   $view_mode = empty($context['view_mode']) ? 'diff_standard' : $context['view_mode'];
207
   $element = field_view_field($context['entity_type'], $entity, $context['field']['field_name'], $view_mode, $langcode);
208

  
209
   foreach (element_children($element) as $delta) {
210
     $diff_items[$delta] = drupal_render($element[$delta]);
211
   }
210
  $entity = clone $context['entity'];
211
  $langcode = field_language($context['entity_type'], $entity, $context['field']['field_name']);
212
  $view_mode = empty($context['view_mode']) ? 'diff_standard' : $context['view_mode'];
213
  $element = field_view_field($context['entity_type'], $entity, $context['field']['field_name'], $view_mode, $langcode);
214

  
215
  foreach (element_children($element) as $delta) {
216
    $diff_items[$delta] = drupal_render($element[$delta]);
217
  }
212 218
  return $diff_items;
213 219
}
214 220

  
215 221
/**
216 222
 * Helper function to get the settings for a given field or formatter.
217 223
 *
218
 * @param array $context
224
 * @param array $field_context
219 225
 *   This will get the settings for a field.
220 226
 *   - field (required): The field that the items belong to.
221 227
 *   - entity: The entity that we are looking up.
......
274 280
    ),
275 281
  );
276 282

  
277
  /*
278
This would be cool, but to do anything else than inline with the text appears
279
to be very hard, requiring a refactoring of both the modules API but also the
280
DiffFormatter and Diff classes. Diff 8.x-4.x maybe.
281

  
282
  $subform['show_delta'] = array(
283
    '#type' => 'checkbox',
284
    '#title' => t('Show delta values'),
285
    '#default_value' => $settings['show_delta'],
286
  );
287
  $subform['delta_format'] = array(
288
    '#type' => 'radios',
289
    '#title' => t('Delta insertion method'),
290
    '#default_value' => $settings['delta_format'],
291
    '#options' => array(
292
      'inline' => t('Prefix to item'),
293
      'row' => t('Individual row'),
294
    ),
295
    '#states' => array(
296
      'invisible' => array(
297
        "input[id$='show-delta']" => array('checked' => FALSE),
298
      ),
299
    ),
300
  );
301
  */
302 283
}
303 284

  
304 285
/**
......
323 304
    'markdown' => function_exists($func) ? '' : 'drupal_html_to_text',
324 305
    'line_counter' => '',
325 306
    'show_header' => 1,
326
    // Can we? This seems too hard to track in the DiffFormatter as all we
327
    // have is a string or an array of strings.
328
    //'show_delta' => 0,
329
    //'delta_format' => 'row',
330 307
  );
308

  
331 309
  return $settings;
332 310
}
333 311

  

Formats disponibles : Unified diff