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
23 * This example demonstrates how migration_lookup process plugin can be applied
24 * on the following source data.
34 * [description] => "File number 1"
40 * [description] => "File number 2"
46 * The sub_process process plugin will take these arrays one at a time and run
47 * its own process for each of them:
55 * plugin: migration_lookup
59 * description: description
61 * In this case, each item in the upload array will be processed by the
62 * sub_process process plugin. The target_id will be found by looking up the
63 * destination value from a previous migration using the migration_lookup
64 * process plugin. The display and description fields will be mapped directly.
68 * Drupal 6 filter formats contain a list of filters belonging to that format
69 * identified by a numeric delta. A delta of 1 indicates automatic linebreaks,
70 * delta of 2 indicates the URL filter and so on. This example demonstrates how
71 * static_map process plugin can be applied on the following source data.
76 * [name] => Filtered HTML
96 * The sub_process will take these arrays one at a time and run its own process
101 * plugin: sub_process
111 * 0: filter_html_escape
114 * 3: filter_htmlcorrector
115 * 4: filter_html_escape
119 * The example above means that we take each array element ([0], [1], etc.) from
120 * the source filters field and apply the static_map plugin on it. Let's have a
121 * closer look at the first array at index 0:
130 * The static_map process plugin results to value 'filter_url' for this input
131 * based on the 'module' and 'delta' map.
135 * Normally the array returned from sub_process will have its original keys. If
136 * you need to change the key, it is possible for the returned array to be keyed
137 * by one of the transformed values in the sub-array. For the same source data
138 * used in the previous example, the migration below would result to keys
139 * 'filter_2' and 'filter_0'.
143 * plugin: sub_process
155 * @see \Drupal\migrate\Plugin\migrate\process\MigrationLookup
156 * @see \Drupal\migrate\Plugin\migrate\process\StaticMap
157 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
159 * @MigrateProcessPlugin(
160 * id = "sub_process",
161 * handle_multiples = TRUE
164 class SubProcess extends ProcessPluginBase {
169 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
171 if (is_array($value) || $value instanceof \Traversable) {
172 foreach ($value as $key => $new_value) {
173 $new_row = new Row($new_value, []);
174 $migrate_executable->processRow($new_row, $this->configuration['process']);
175 $destination = $new_row->getDestination();
176 if (array_key_exists('key', $this->configuration)) {
177 $key = $this->transformKey($key, $migrate_executable, $new_row);
179 $return[$key] = $destination;
186 * Runs the process pipeline for the key to determine its dynamic name.
188 * @param string|int $key
190 * @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable
191 * The migrate executable helper class.
192 * @param \Drupal\migrate\Row $row
193 * The current row after processing.
196 * The transformed key.
198 protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) {
199 $process = ['key' => $this->configuration['key']];
200 $migrate_executable->processRow($row, $process, $key);
201 return $row->getDestinationProperty('key');
207 public function multiple() {