You are here

unique.inc in Feeds Tamper 7

Same filename and directory in other branches
  1. 6 plugins/unique.inc

File

plugins/unique.inc
View source
<?php

/**
 * @file
 * Ensure a multi-valued field has unique values.
 */
$plugin = array(
  'form' => 'feeds_tamper_unique_form',
  'callback' => 'feeds_tamper_unique_callback',
  'name' => 'Unique',
  'multi' => 'direct',
  'single' => 'skip',
  'category' => 'List',
);
function feeds_tamper_unique_form($importer, $element_key, $settings) {
  $form = array();
  $form['unique']['#markup'] = t('Makes the elements in a multivalued field unique.');
  return $form;
}
function feeds_tamper_unique_callback($result, $item_key, $element_key, &$field, $settings, $source) {
  $unique = array();
  foreach ($field as $f) {
    if (!in_array($f, $unique)) {
      $unique[] = $f;
    }
  }
  $field = $unique;
}