diff --git a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php index a5fb4d4..46b6e29 100644 --- a/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +++ b/core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php @@ -8,6 +8,11 @@ /** * Drupal 7 field instances source from database. * + * @internal + * + * This class is marked as internal and should not be extended. Use + * Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase instead. + * * @MigrateSource( * id = "d7_field_instance", * source_provider = "field" @@ -43,6 +48,28 @@ public function query() { /** * {@inheritdoc} */ + protected function initializeIterator() { + $results = $this->prepareQuery()->execute()->fetchAll(); + + // Group all instances by their base field. + $instances = []; + foreach ($results as $result) { + $instances[$result['field_id']][] = $result; + } + + // Add the array of all instances using the same base field to each row. + $rows = []; + foreach ($results as $result) { + $result['instances'] = $instances[$result['field_id']]; + $rows[] = $result; + } + + return new \ArrayIterator($rows); + } + + /** + * {@inheritdoc} + */ public function fields() { return [ 'id' => $this->t('The field instance ID.'), diff --git a/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldInstanceTest.php index e08f0b0..895fe3f 100644 --- a/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Plugin/migrate/source/d7/FieldInstanceTest.php @@ -68,6 +68,7 @@ public function providerSource() { 'bundle' => 'page', 'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}', 'deleted' => '0', + 'type' => 'text_with_summary', 'label' => 'Body', 'widget' => [ 'type' => 'text_textarea_with_summary', @@ -118,6 +119,18 @@ public function providerSource() { 'translatable' => '0', 'deleted' => '0', ], + 'instances' => [ + [ + 'id' => '2', + 'field_id' => '2', + 'field_name' => 'body', + 'entity_type' => 'node', + 'bundle' => 'page', + 'data' => 'a:6:{s:5:"label";s:4:"Body";s:6:"widget";a:4:{s:4:"type";s:26:"text_textarea_with_summary";s:8:"settings";a:2:{s:4:"rows";i:20;s:12:"summary_rows";i:5;}s:6:"weight";i:-4;s:6:"module";s:4:"text";}s:8:"settings";a:3:{s:15:"display_summary";b:1;s:15:"text_processing";i:1;s:18:"user_register_form";b:0;}s:7:"display";a:2:{s:7:"default";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:12:"text_default";s:8:"settings";a:0:{}s:6:"module";s:4:"text";s:6:"weight";i:0;}s:6:"teaser";a:5:{s:5:"label";s:6:"hidden";s:4:"type";s:23:"text_summary_or_trimmed";s:8:"settings";a:1:{s:11:"trim_length";i:600;}s:6:"module";s:4:"text";s:6:"weight";i:0;}}s:8:"required";b:0;s:11:"description";s:0:"";}', + 'deleted' => '0', + 'type' => 'text_with_summary', + ], + ], ], ];