public function CFDefaultFieldComparator::runFieldComparison in Changed Fields API 7.2
Same name and namespace in other branches
- 7.3 src/FieldComparator/CFDefaultFieldComparator.php \CFDefaultFieldComparator::runFieldComparison()
- 7 includes/changed_fields.core.inc \CFDefaultFieldComparator::runFieldComparison()
Method that runs comparison of field values.
Parameters
array $fieldInfo: Array contains field instance and field base information.
mixed $oldValue: Old field value to compare.
mixed $newValue: Old field value to compare.
Return value
array|bool TRUE if fields are identical or array with differences if fields are different.
File
- includes/
changed_fields.core.inc, line 241 - File contains core classes and interfaces.
Class
- CFDefaultFieldComparator
- Class CFDefaultFieldComparator.
Code
public function runFieldComparison(array $fieldInfo, $oldValue, $newValue) {
$similarFields = TRUE;
if ($fieldInfo['field_base']['type'] == 'field_collection') {
// If collection was added or removed then we have already
// different collections.
if (!$oldValue && $newValue || $oldValue && !$newValue) {
$similarFields = $this
->makeResultArray($fieldInfo['field_base']['type'], $oldValue, $newValue);
}
else {
if ($oldValue && $newValue) {
// If value was added|removed to|from multi-value field then we have
// already different values.
if (count($newValue) != count($oldValue)) {
$similarFields = $this
->makeResultArray($fieldInfo['field_base']['type'], $oldValue, $newValue);
}
else {
foreach ($oldValue as $key => $fc) {
if (is_array($similarFields)) {
break;
}
$oldFc = entity_load('field_collection_item', array(
$fc['value'],
));
$oldFc = reset($oldFc);
$newFc = $newValue[$key]['entity'];
$fcFields = field_info_instances('field_collection_item', $fieldInfo['field_base']['field_name']);
foreach ($fcFields as $fcFieldName => $fcFieldData) {
$fcFieldData = field_info_field($fcFieldName);
$oldFcFieldValue = field_get_items('field_collection_item', $oldFc, $fcFieldName);
$newFcFieldValue = field_get_items('field_collection_item', $newFc, $fcFieldName);
$similarFields = $this
->runFieldComparison($fcFieldData, $oldFcFieldValue, $newFcFieldValue);
// If changes have been detected.
if (is_array($similarFields)) {
// Make result array with old and new
// field collection entities.
$similarFields = $this
->makeResultArray($fieldInfo['field_base']['type'], $oldValue, $newValue);
break;
}
}
}
}
}
}
}
else {
$similarFields = $this
->compareFieldValues($fieldInfo, $oldValue, $newValue);
}
return $similarFields;
}