You are here

function content_diff in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6 includes/content.diff.inc \content_diff()
  2. 6.2 includes/content.diff.inc \content_diff()

Implementation of hook_diff()

1 string reference to 'content_diff'
content_init in ./content.module
Implementation of hook_init().

File

includes/content.diff.inc, line 13
hook_diff() implementations for CCK (especially fields).

Code

function content_diff($old_node, $new_node) {
  $result = array();

  // Prevent against invalid 'nodes' built by broken 3rd party code.
  if (isset($new_node->type)) {
    $type = content_types($new_node->type);
    $field_types = _content_field_types();
    foreach ($type['fields'] as $field) {

      // Ignore fields the current user is not allowed to view.
      if (!content_access('view', $field, NULL, $new_node)) {
        continue;
      }
      $function = $field_types[$field['type']]['module'] . '_content_diff_values';
      $function = function_exists($function) ? $function : 'content_content_diff_values';
      $old_values = array();
      $new_values = array();
      if (isset($old_node->{$field}['field_name'])) {
        $old_values = $function($old_node, $field, $old_node->{$field}['field_name']);
      }
      if (isset($new_node->{$field}['field_name'])) {
        $new_values = $function($new_node, $field, $new_node->{$field}['field_name']);
      }
      if ($old_values || $new_values) {
        $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;
}