3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\ProcessPluginBase;
8 use Drupal\migrate\Row;
11 * Concatenates a set of strings.
13 * The concat plugin is used to concatenate strings. For example, imploding a
14 * set of strings into a single string.
16 * Available configuration keys:
17 * - delimiter: (optional) A delimiter, or glue string, to insert between the
31 * This will set new_text_field to the concatenation of the 'foo' and 'bar'
32 * source values. For example, if the 'foo' property is "wambooli" and the 'bar'
33 * property is "pastafazoul", new_text_field will be "wamboolipastafazoul".
35 * You can also specify a delimiter.
47 * This will set new_text_field to the concatenation of the 'foo' source value,
48 * the delimiter and the 'bar' source value. For example, using the values above
49 * and "/" as the delimiter, if the 'foo' property is "wambooli" and the 'bar'
50 * property is "pastafazoul", new_text_field will be "wambooli/pastafazoul".
52 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
54 * @MigrateProcessPlugin(
56 * handle_multiples = TRUE
59 class Concat extends ProcessPluginBase {
64 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
65 if (is_array($value)) {
66 $delimiter = isset($this->configuration['delimiter']) ? $this->configuration['delimiter'] : '';
67 return implode($delimiter, $value);
70 throw new MigrateException(sprintf('%s is not an array', var_export($value, TRUE)));