You are here

public function FeedImportMergeDuplicates::merge in Feed Import 8

Merge the new and current field values. The merge should be set in $current ref. variable

Parameters

array $current: Current field values

array $new: New field values

array $field: Field info cardinality - field cardinality compare - compare function for field value

Return value

bool True if $current was changed

Overrides FeedImportMergeField::merge

File

feed_import_base/src/FeedImportMergeDuplicates.php, line 12

Class

FeedImportMergeDuplicates
Class which merges field values without checking for duplicates.

Namespace

Drupal\feed_import_base

Code

public function merge(array &$current, array &$new, array &$field) {
  if ($field['cardinality'] == -1) {
    $current = array_merge($current, $new);
    return TRUE;
  }
  elseif (($cnt = count($current)) < $field['cardinality']) {
    $cnt = $field['cardinality'] - $cnt;
    $current = array_merge($current, count($new) <= $cnt ? $new : array_slice($new, 0, $cnt));
    return TRUE;
  }
  return FALSE;
}