You are here

private function CFDefaultFieldComparator::compareFieldValues in Changed Fields API 7

Same name and namespace in other branches
  1. 7.3 src/FieldComparator/CFDefaultFieldComparator.php \CFDefaultFieldComparator::compareFieldValues()
  2. 7.2 includes/changed_fields.core.inc \CFDefaultFieldComparator::compareFieldValues()

Method that compares old and new field values.

Parameters

$fieldType:

$oldValue:

$newValue:

Return value

array|bool

1 call to CFDefaultFieldComparator::compareFieldValues()
CFDefaultFieldComparator::runFieldComparison in includes/changed_fields.core.inc
Method that runs comparison of field values.

File

includes/changed_fields.core.inc, line 350
changed_fields.core.inc file.

Class

CFDefaultFieldComparator
Class CFDefaultFieldComparator.

Code

private function compareFieldValues($fieldType, $oldValue, $newValue) {
  $result = TRUE;
  $properties = $this
    ->getComparableProperties($fieldType);

  // If value was added or removed then we have already different values.
  if (!$oldValue && $newValue || $oldValue && !$newValue) {
    $result = $this
      ->makeResultArray($fieldType, $oldValue, $newValue);
  }
  else {
    if ($oldValue && $newValue) {

      // Simple comparison (for title).
      if (empty($properties)) {
        if ($newValue != $oldValue) {
          $result = $this
            ->makeResultArray($fieldType, $oldValue, $newValue);
        }
      }
      else {

        // If value was added|removed to|from multi-value field then we have
        // already different values.
        if (count($newValue) != count($oldValue)) {
          $result = $this
            ->makeResultArray($fieldType, $oldValue, $newValue);
        }
        else {

          // Walk through each field value and compare it's properties.
          foreach ($newValue as $key => $value) {
            if (is_array($result)) {
              break;
            }
            foreach ($properties as $property) {
              if ($newValue[$key][$property] != $oldValue[$key][$property]) {
                $result = $this
                  ->makeResultArray($fieldType, $oldValue, $newValue);
                break;
              }
            }
          }
        }
      }
    }
  }
  return $result;
}