3 namespace Drupal\migrate\Plugin\migrate\process;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
10 * Runs an array of arrays through its own process pipeline.
12 * The sub_process plugin accepts an array of associative arrays and runs each
13 * one through its own process pipeline, producing a newly keyed associative
14 * array of transformed values.
16 * Available configuration keys:
17 * - process: the plugin(s) that will process each element of the source.
18 * - key: runs the process pipeline for the key to determine a new dynamic
32 * [description] => "File number 1"
38 * [description] => "File number 2"
45 * The sub_process process plugin will take these arrays one at a time and run
46 * its own process over each one:
55 * plugin: migration_lookup
59 * description: description
62 * In this case, each item in the upload array will be processed by the
63 * sub_process process plugin. The target_id will be found by looking up the
64 * destination value from a previous migration. The display and description
65 * fields will simply be mapped.
67 * In the next example, normally the array returned from sub_process will have
68 * its original keys. If you need to change the key, it is possible for the
69 * returned array to be keyed by one of the transformed values in the sub-array.
75 * [name] => Filtered HTML
109 * In the above example, the keys of the returned array would be filter_2 and
112 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
114 * @MigrateProcessPlugin(
115 * id = "sub_process",
116 * handle_multiples = TRUE
119 class SubProcess extends ProcessPluginBase {
124 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
126 if (is_array($value) || $value instanceof \Traversable) {
127 foreach ($value as $key => $new_value) {
128 $new_row = new Row($new_value, []);
129 $migrate_executable->processRow($new_row, $this->configuration['process']);
130 $destination = $new_row->getDestination();
131 if (array_key_exists('key', $this->configuration)) {
132 $key = $this->transformKey($key, $migrate_executable, $new_row);
134 $return[$key] = $destination;
141 * Runs the process pipeline for the key to determine its dynamic name.
143 * @param string|int $key
145 * @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
146 * The migrate executable helper class.
147 * @param \Drupal\migrate\Row $row
148 * The current row after processing.
151 * The transformed key.
153 protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) {
154 $process = ['key' => $this->configuration['key']];
155 $migrate_executable->processRow($row, $process, $key);
156 return $row->getDestinationProperty('key');
162 public function multiple() {