You are here

private function CFDefaultFieldComparator::compareFieldValues in Changed Fields API 7.3

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

Method that compares old and new field values.

Parameters

array $fieldInfo: Array contains field instance and field base information.

mixed $oldValue: Old field value to compare.

mixed $newValue: New field value to compare.

Return value

array|bool TRUE if fields are identical or array with differences if fields are different.

1 call to CFDefaultFieldComparator::compareFieldValues()
CFDefaultFieldComparator::runFieldComparison in src/FieldComparator/CFDefaultFieldComparator.php
Method that runs comparison of field values.

File

src/FieldComparator/CFDefaultFieldComparator.php, line 222

Class

CFDefaultFieldComparator
Class CFDefaultFieldComparator.

Code

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

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

      // Simple comparison (for title).
      if (empty($properties) && $fieldInfo['field_base']['type'] == 'title') {
        if ($newValue != $oldValue) {
          $result = $this
            ->makeResultArray($fieldInfo['field_base']['type'], $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($fieldInfo['field_base']['type'], $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 (array_key_exists($property, $newValue[$key]) && array_key_exists($property, $oldValue[$key]) && $newValue[$key][$property] != $oldValue[$key][$property]) {
                $result = $this
                  ->makeResultArray($fieldInfo['field_base']['type'], $oldValue, $newValue);
                break;
              }
            }
          }
        }
      }
    }
  }
  return $result;
}