function diff_compare_entities in Diff 7.3
Generic callback to compare two entities.
1 call to diff_compare_entities()
- diff_entity_body_rows in ./
diff.pages.inc - Creates an array of rows which represent the difference between two entities.
File
- ./
diff.pages.inc, line 422 - Menu callbacks for hook_menu().
Code
function diff_compare_entities($left_entity, $right_entity, $context) {
$entity_type = $context['entity_type'];
list(, , $bundle) = entity_extract_ids($entity_type, $right_entity);
$context['bundle'] = $bundle;
$context['old_entity'] = $left_entity;
$context['new_entity'] = $right_entity;
$context += array(
'states' => array(
'raw',
),
'view_mode' => FALSE,
'language' => LANGUAGE_NONE,
);
$diff = module_invoke_all('entity_diff', $left_entity, $right_entity, $context);
// Allow other modules to interact directly with the results.
drupal_alter('entity_diff', $diff, $context);
// We start off assuming all form elements are in the correct order.
$diff['#sorted'] = TRUE;
// Field rows. Recurse through all child elements.
$count = 0;
foreach (element_children($diff) as $key) {
if (!isset($diff[$key]['#states'])) {
$diff[$key]['#states'] = array();
}
// Ensure that the element follows the new #states format.
if (isset($diff[$key]['#old'])) {
$diff[$key]['#states']['raw']['#old'] = $diff[$key]['#old'];
unset($diff[$key]['#old']);
}
if (isset($diff[$key]['#new'])) {
$diff[$key]['#states']['raw']['#new'] = $diff[$key]['#new'];
unset($diff[$key]['#new']);
}
// If requested, we can convert the .
foreach (array(
'raw',
'rendered',
) as $state) {
if (in_array($state . '_plain', $context['states'])) {
diff_markdown_state($diff[$key], $state);
}
}
// Assign a decimal placeholder weight to preserve original array order.
if (!isset($diff[$key]['#weight'])) {
$diff[$key]['#weight'] = $count / 1000;
}
else {
// If one child element has a weight then we will need to sort later.
unset($diff['#sorted']);
}
$count++;
}
// One of the children has a #weight.
if (!isset($diff['#sorted'])) {
uasort($diff, 'element_sort');
}
else {
unset($diff['#sorted']);
}
// Process the array and get line counts per field.
array_walk($diff, 'diff_process_state_lines');
return $diff;
}