You are here

FeedImportMergeOverwrite.php in Feed Import 8

File

feed_import_base/src/FeedImportMergeOverwrite.php
View source
<?php

namespace Drupal\feed_import_base;


/**
 * Class which overwrites values. A simple value by value comparison is made.
 * This also overwrites values if missing from 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;
  }

}

Classes

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