You are here

class FeedImportMergeOverwrite in Feed Import 8

Class which overwrites values. A simple value by value comparison is made. This also overwrites values if missing from source.

Hierarchy

Expanded class hierarchy of FeedImportMergeOverwrite

File

feed_import_base/src/FeedImportMergeOverwrite.php, line 8

Namespace

Drupal\feed_import_base
View source
class FeedImportMergeOverwrite extends FeedImportMergeField {

  /**
   * {@inheritdoc}
   */
  public function overwriteEmpty() {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function merge(array &$current, array &$new, array &$field) {
    $cnt = count($new);
    if ($cnt != count($current)) {

      // Different number of values.
      $current = $new;
      return TRUE;
    }

    // Same number of values. Might be the same.
    $changed = FALSE;
    for ($i = 0; $i < $cnt; $i++) {
      if (!$field['compare']($new[$i], $current[$i])) {
        $current[$i] = $new[$i];
        $changed = TRUE;
      }
    }
    return $changed;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FeedImportMergeOverwrite::merge public function Merge the new and current field values. The merge should be set in $current ref. variable Overrides FeedImportMergeField::merge
FeedImportMergeOverwrite::overwriteEmpty public function Remove field if is missing from source. Overrides FeedImportMergeField::overwriteEmpty