A migration processor extends the \Drupal\migrate\ProcessPluginBase class. It expects to implement the transform() function and return the result based on the configuration provided. For example:
<?php
namespace Drupal\migrate\Plugin\migrate\process;
use Drupal\migrate\MigrateException;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Concatenates the strings in the current value.
*
* @MigrateProcessPlugin(
* id = "concat",
* handle_multiples = TRUE
* )
*/
class Concat extends ProcessPluginBase {
/**
* {@inheritdoc}
*
* Concatenates the strings in the current value.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
if (is_array($value)) {
$delimiter = isset($this->configuration['delimiter']) ? $this->configuration['delimiter'] : '';
return implode($delimiter, $value);
}
else {
throw new MigrateException(sprintf('%s is not an array', var_export($value, TRUE)));
}
}
}
The transform() function receives the value from the migration source, a \Drupal\migrate\MigrateExecutableInterface that defines how the migration is being triggered, the migration source row, and the property on the destination entity. Processors implement the \Drupal\migrate\Plugin\MigrateProcessInterface, which specifies the following functions:
- transform(): It returns the modified value
- multiple(): It returns whether the value is treated as a scalar value or an array; the implementation in the ProcessPluginBase class returns FALSE, which would be overridden in circumstances where the processor returns an array