Skip to content

Commit

Permalink
Add process plugin to generate unique array.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Borchert committed Nov 11, 2017
1 parent 19e76aa commit 118445d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/Plugin/migrate/process/ArrayUnique.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Drupal\up_migrate\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
* This plugin removes duplicate values from source value.
*
* @MigrateProcessPlugin(
* id = "array_unique",
* handle_multiples = TRUE
* )
*/
class ArrayUnique extends ProcessPluginBase {

/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (!is_array($value)) {
$value = [$value];
}
return array_unique($value);
}

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

}

0 comments on commit 118445d

Please sign in to comment.