diff --git a/core/modules/file/migration_templates/d6_upload.yml b/core/modules/file/migration_templates/d6_upload.yml index 8289d56..a497099 100644 --- a/core/modules/file/migration_templates/d6_upload.yml +++ b/core/modules/file/migration_templates/d6_upload.yml @@ -9,7 +9,7 @@ process: vid: vid type: type upload: - plugin: iterator + plugin: sub_process source: upload process: target_id: diff --git a/core/modules/migrate/src/Plugin/migrate/process/Iterator.php b/core/modules/migrate/src/Plugin/migrate/process/Iterator.php index adfd367..5400e18 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Iterator.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Iterator.php @@ -2,138 +2,20 @@ namespace Drupal\migrate\Plugin\migrate\process; -use Drupal\migrate\ProcessPluginBase; -use Drupal\migrate\MigrateExecutableInterface; -use Drupal\migrate\Row; +@trigger_error('The ' . __NAMESPACE__ . '\Iterator is deprecated in +Drupal 8.4.x and will be removed before Drupal 9.0.0. Instead, use ' . __NAMESPACE__ . '\SubProcess', E_USER_DEPRECATED); /** * Iterates and processes an associative array. * - * The iterator process plugin allows sub-processing of a list of associative - * arrays. Often source data will include multiple-value properties as - * associative arrays. For example, for file uploads on Drupal 6, the upload - * property contains a list of sub-properties. + * @deprecated in Drupal 8.4.x and will be removed in Drupal 9.0.x. Use + * \Drupal\migrate\Plugin\migrate\process\SubProcess instead. * - * Available configuration keys: - * - process: the plugin(s) that will process each element of the source. - * - key: runs the process pipeline for the defined key. - * - * Examples: - * - * @code - * source: Array - * ( - * [upload] => Array - * ( - * [0] => Array - * ( - * [fid] => 1 - * [list] => 0 - * [description] => "File number 1" - * ) - * [1] => Array - * ( - * [fid] => 2 - * [list] => 1 - * [description] => "File number 2" - * ) - * ) - * ) - * ... - * @endcode - * - * The iterator process plugin will take these arrays one at a time and run its - * own process over each one: - * - * @code - * process: - * upload: - * plugin: iterator - * source: upload - * process: - * target_id: - * plugin: migration_lookup - * migration: d6_file - * source: fid - * display: list - * description: description - * @endcode - * - * In this case, each item in the upload array will be processed bye the - * iterator process plugin. The target_id will be found by looking up the - * destination value from a previous migration. The display and description - * fields will simply be mapped. - * - * The mapping values passed to iterator are special. Numeric values may not be - * used. - * - * @code - * field_relationship: - - - plugin: migration_lookup - * migration: - * - migration_page - * - migration_blog - * source: nid - * - - * plugin: iterator - * process: - * target_id: '0' - * @endcode - * In the migration above, the value mapped to target_id is intentionally '0'. - * - * @see \Drupal\migrate\Plugin\MigrateProcessInterface + * @see https://www.drupal.org/node/2880427 * * @MigrateProcessPlugin( * id = "iterator", * handle_multiples = TRUE * ) */ -class Iterator extends ProcessPluginBase { - - /** - * Runs a process pipeline on each destination property per list item. - */ - public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - $return = []; - if (!is_null($value)) { - foreach ($value as $key => $new_value) { - $new_row = new Row($new_value, []); - $migrate_executable->processRow($new_row, $this->configuration['process']); - $destination = $new_row->getDestination(); - if (array_key_exists('key', $this->configuration)) { - $key = $this->transformKey($key, $migrate_executable, $new_row); - } - $return[$key] = $destination; - } - } - return $return; - } - - /** - * Runs the process pipeline for the current key. - * - * @param string|int $key - * The current key. - * @param \Drupal\migrate\MigrateExecutableInterface $migrate_executable - * The migrate executable helper class. - * @param \Drupal\migrate\Row $row - * The current row after processing. - * - * @return mixed - * The transformed key. - */ - protected function transformKey($key, MigrateExecutableInterface $migrate_executable, Row $row) { - $process = ['key' => $this->configuration['key']]; - $migrate_executable->processRow($row, $process, $key); - return $row->getDestinationProperty('key'); - } - - /** - * {@inheritdoc} - */ - public function multiple() { - return TRUE; - } - -} +class Iterator extends SubProcess {} diff --git a/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php b/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php index adfd367..01ee026 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php +++ b/core/modules/migrate/src/Plugin/migrate/process/SubProcess.php @@ -7,9 +7,9 @@ use Drupal\migrate\Row; /** - * Iterates and processes an associative array. + * Processes a row of data as a sub-process. * - * The iterator process plugin allows sub-processing of a list of associative + * The sub_process process plugin allows sub-processing of a list of associative * arrays. Often source data will include multiple-value properties as * associative arrays. For example, for file uploads on Drupal 6, the upload * property contains a list of sub-properties. @@ -42,13 +42,13 @@ * ... * @endcode * - * The iterator process plugin will take these arrays one at a time and run its - * own process over each one: + * The sub_process process plugin will take these arrays one at a time and run + * its own process over each one: * * @code * process: * upload: - * plugin: iterator + * plugin: sub_process * source: upload * process: * target_id: @@ -60,12 +60,12 @@ * @endcode * * In this case, each item in the upload array will be processed bye the - * iterator process plugin. The target_id will be found by looking up the + * sub_process process plugin. The target_id will be found by looking up the * destination value from a previous migration. The display and description * fields will simply be mapped. * - * The mapping values passed to iterator are special. Numeric values may not be - * used. + * The mapping values passed to sub_process are special. Numeric values may not + * be used. * * @code * field_relationship: @@ -76,7 +76,7 @@ * - migration_blog * source: nid * - - * plugin: iterator + * plugin: sub_process * process: * target_id: '0' * @endcode @@ -85,11 +85,11 @@ * @see \Drupal\migrate\Plugin\MigrateProcessInterface * * @MigrateProcessPlugin( - * id = "iterator", + * id = "sub_process", * handle_multiples = TRUE * ) */ -class Iterator extends ProcessPluginBase { +class SubProcess extends ProcessPluginBase { /** * Runs a process pipeline on each destination property per list item. diff --git a/core/modules/migrate/tests/src/Unit/process/IteratorTest.php b/core/modules/migrate/tests/src/Unit/process/IteratorTest.php index 993fb92..46daade 100644 --- a/core/modules/migrate/tests/src/Unit/process/IteratorTest.php +++ b/core/modules/migrate/tests/src/Unit/process/IteratorTest.php @@ -31,6 +31,8 @@ class IteratorTest extends MigrateTestCase { /** * Tests the iterator process plugin. + * + * @group legacy */ public function testIterator() { $migration = $this->getMigration(); diff --git a/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php b/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php index 993fb92..791bded 100644 --- a/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php +++ b/core/modules/migrate/tests/src/Unit/process/SubProcessTest.php @@ -4,21 +4,21 @@ use Drupal\migrate\MigrateExecutable; use Drupal\migrate\Plugin\migrate\process\Get; -use Drupal\migrate\Plugin\migrate\process\Iterator; +use Drupal\migrate\Plugin\migrate\process\SubProcess; use Drupal\migrate\Row; use Drupal\Tests\migrate\Unit\MigrateTestCase; /** - * Tests the iterator process plugin. + * Tests the sub_process process plugin. * * @group migrate */ -class IteratorTest extends MigrateTestCase { +class SubProcessTest extends MigrateTestCase { /** - * The iterator plugin being tested. + * The sub_process plugin being tested. * - * @var \Drupal\migrate\Plugin\migrate\process\TestIterator + * @var \Drupal\migrate\Plugin\migrate\process\SubProcess */ protected $plugin; @@ -30,11 +30,11 @@ class IteratorTest extends MigrateTestCase { ]; /** - * Tests the iterator process plugin. + * Tests the sub_process process plugin. */ - public function testIterator() { + public function testSubProcess() { $migration = $this->getMigration(); - // Set up the properties for the iterator. + // Set up the properties for the sub_process. $configuration = [ 'process' => [ 'foo' => 'source_foo', @@ -42,15 +42,15 @@ public function testIterator() { ], 'key' => '@id', ]; - $plugin = new Iterator($configuration, 'iterator', []); + $plugin = new SubProcess($configuration, 'sub_process', []); // Manually create the plugins. Migration::getProcessPlugins does this // normally but the plugin system is not available. foreach ($configuration['process'] as $destination => $source) { - $iterator_plugins[$destination][] = new Get(['source' => $source], 'get', []); + $sub_process_plugins[$destination][] = new Get(['source' => $source], 'get', []); } $migration->expects($this->at(1)) ->method('getProcessPlugins') - ->will($this->returnValue($iterator_plugins)); + ->will($this->returnValue($sub_process_plugins)); // Set up the key plugins. $key_plugin['key'][] = new Get(['source' => '@id'], 'get', []); $migration->expects($this->at(2))