3 namespace Drupal\migrate_plus\Plugin\migrate\process;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateException;
7 use Drupal\migrate\MigrateExecutableInterface;
8 use Drupal\migrate\Row;
11 * This plugin merges arrays together.
13 * @MigrateProcessPlugin(
17 * Use to merge several fields into one. In the following example, imagine a D7
18 * node with a field_collections field and an image field that migrations were
19 * written for to make paragraph entities in D8. We would like to add those
20 * paragraph entities to the 'paragraphs_field'. Consider the following:
27 * source: field_section
30 * plugin: migration_lookup
31 * migration: field_collection_field_section_to_paragraph
38 * plugin: migration_lookup
39 * migration: image_entities_to_paragraph
47 * plugin: 'entity:node'
49 class Merge extends ProcessPluginBase {
54 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
55 if (!is_array($value)) {
56 throw new MigrateException(sprintf('Merge process failed for destination property (%s): input is not an array.', $destination_property));
59 foreach($value as $i => $item) {
60 if (!is_array($item)) {
61 throw new MigrateException(sprintf('Merge process failed for destination property (%s): index (%s) in the source value is not an array that can be merged.', $destination_property, $i));
63 $new_value = array_merge($new_value, $item);