You are here

function content_diff in Diff 6

Same name and namespace in other branches
  1. 5.2 cck.inc \content_diff()
  2. 5 cck.inc \content_diff()

Implementation of hook_diff()

File

./cck.inc, line 13
hook_diff() implementations for CCK (especially fields).

Code

function content_diff(&$old_node, &$new_node) {
  $result = array();
  $cck_info = content_types($new_node->type);
  if ($cck_info) {
    foreach ($cck_info['fields'] as $field) {
      $old_values = array();
      $new_values = array();
      switch ($field['type']) {
        case 'nodereference':
          if (isset($old_node->{$field}['field_name'])) {
            $old_values = _cck_nodereference_diff_values($old_node, $field);
          }
          if (isset($new_node->{$field}['field_name'])) {
            $new_values = _cck_nodereference_diff_values($new_node, $field);
          }
          break;
        case 'userreference':
          if (isset($old_node->{$field}['field_name'])) {
            $old_values = _cck_userreference_diff_values($old_node, $field);
          }
          if (isset($new_node->{$field}['field_name'])) {
            $new_values = _cck_userreference_diff_values($new_node, $field);
          }
          break;
        case 'number_integer':
        case 'text':
          if (isset($old_node->{$field}['field_name'])) {
            $old_values = _cck_text_diff_values($old_node, $field);
          }
          if (isset($new_node->{$field}['field_name'])) {
            $new_values = _cck_text_diff_values($new_node, $field);
          }
          break;
        case 'link':
          if (isset($old_node->{$field}['field_name'])) {
            $old_values = _cck_link_diff_values($old_node, $field);
          }
          if (isset($new_node->{$field}['field_name'])) {
            $new_values = _cck_link_diff_values($new_node, $field);
          }
          break;
      }
      $result[$field['field_name']] = array(
        '#name' => $field['widget']['label'],
        '#old' => $old_values,
        '#new' => $new_values,
        '#weight' => $field['widget']['weight'],
        '#format' => array(
          'show_header' => false,
        ),
      );
    }
  }
  return $result;
}