diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php index 004b92c..70a9d4f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php @@ -2,11 +2,7 @@ namespace Drupal\Core\Field\Plugin\migrate\cckfield; -use Drupal\migrate\Plugin\MigrateProcessInterface; -use Drupal\migrate\Plugin\Migration; use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\MigrateExecutable; -use Drupal\migrate\MigrateMessage; use Drupal\migrate\Row; /** @@ -21,6 +17,8 @@ class NodeReference extends ReferenceBase { /** + * The plugin id for the node type migration. + * * @var string */ protected $nodeTypeMigration = 'd6_node_type'; @@ -72,47 +70,9 @@ public function transformFieldInstanceSettings(Row $row) { $node_types = array_filter($source_settings['referenceable_types']); if (!empty($node_types)) { - $settings['handler_settings']['target_bundles'] = $this->migrateNodeTypes($node_types); + $settings['handler_settings']['target_bundles'] = $this->lookupMigrations($this->nodeTypeMigration, $node_types); } return $settings; } - /** - * Look up migrated node types from the d6_node_type migration. - * - * @param $source_node_types - * The source node types. - * - * @return array - * The migrated node types. - */ - protected function migrateNodeTypes($source_node_types) { - // Configure the migration process plugin to look up migrated IDs from - // the d6_node_type migration. - $migration_plugin_configuration = [ - 'migration' => $this->nodeTypeMigration, - ]; - - $row = new Row([], []); - - /** - * @var MigrationInterface $migration - */ - $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]); - - /** - * @var MigrateProcessInterface $migrationProcessPlugin - */ - $migrationProcessPlugin = $this->migratePluginManager - ->createInstance('migration', $migration_plugin_configuration, $migration); - - $executable = new MigrateExecutable($migration, new MigrateMessage()); - - $node_types = []; - foreach ($source_node_types as $node_type) { - $node_types[] = $migrationProcessPlugin->transform($node_type, $executable, $row, NULL); - } - return array_combine($node_types, $node_types); - } - } diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php index 9ee4a73..e19e5c0 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php @@ -3,8 +3,12 @@ namespace Drupal\Core\Field\Plugin\migrate\cckfield; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; +use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\MigrateMessage; use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigratePluginManager; +use Drupal\migrate\Plugin\MigrationPluginManagerInterface; +use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,18 +18,25 @@ abstract class ReferenceBase extends CckFieldPluginBase implements ContainerFactoryPluginInterface { /** - * The migrate plugin manager, configured for lookups in d6_user_roles. + * The migration plugin manager. + * @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface + */ + protected $migrationPluginManager; + + /** + * The migrate process plugin manager. * * @var \Drupal\migrate\Plugin\MigratePluginManager */ - protected $migratePluginManager; + protected $migrateProcessPluginManager; /** * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, MigratePluginManager $migration_plugin_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationPluginManagerInterface $migration_plugin_manager, MigratePluginManager $migrate_process_plugin_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->migratePluginManager = $migration_plugin_manager; + $this->migrationPluginManager = $migration_plugin_manager; + $this->migrateProcessPluginManager = $migrate_process_plugin_manager; } /** @@ -36,6 +47,7 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, + $container->get('plugin.manager.migration'), $container->get('plugin.manager.migrate.process') ); } @@ -51,21 +63,57 @@ public static function create(ContainerInterface $container, array $configuratio * {@inheritdoc} */ public function getFieldFormatterMap() { - return array(); + return []; } /** * {@inheritdoc} */ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { - $process = array( + $process = [ 'plugin' => 'iterator', 'source' => $field_name, 'process' => array( 'target_id' => $this->entityId(), ), - ); + ]; $migration->setProcessOfProperty($field_name, $process); } + /** + * Look up migrated role IDs from the d6_user_role migration. + * + * @param string $migration_id + * The migration id which migrated the source. + * @param array $source_ids + * The source IDs. + * + * @return array + * The migrated IDs. + */ + protected function lookupMigrations($migration_id, $source_ids) { + // Configure the migration process plugin to look up migrated IDs from + // the d6_user_role migration. + $migration_plugin_configuration = [ + 'migration' => $migration_id, + ]; + + $row = new Row([], []); + + /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ + $migration = $this->migrationPluginManager->createStubMigration([]); + + /** @var \Drupal\migrate\Plugin\MigrateProcessInterface $migrationProcessPlugin */ + $migrationProcessPlugin = $this->migrateProcessPluginManager + ->createInstance('migration', $migration_plugin_configuration, $migration); + + $executable = new MigrateExecutable($migration, new MigrateMessage()); + + $ids = []; + foreach ($source_ids as $source_id) { + $ids[] = $migrationProcessPlugin->transform($source_id, $executable, $row, NULL); + } + return array_combine($ids, $ids); + } + } diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php index 13e921c..7581e2e 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php @@ -1,10 +1,5 @@ migrateUserRoles($roles); + $settings['handler_settings']['filter']['role'] = $this->lookupMigrations($this->userRoleMigration, $roles); } return $settings; } - /** - * Look up migrated role IDs from the d6_user_role migration. - * - * @param $source_roles - * The source role IDs. - * - * @return array - * The migrated role IDs. - */ - protected function migrateUserRoles($source_roles) { - // Configure the migration process plugin to look up migrated IDs from - // the d6_user_role migration. - $migration_plugin_configuration = [ - 'migration' => $this->userRoleMigration, - ]; - - $row = new Row([], []); - - /** - * @var MigrationInterface $migration - */ - $migration = \Drupal::service('plugin.manager.migration')->createStubMigration([]); - - /** - * @var MigrateProcessInterface $migrationProcessPlugin - */ - $migrationProcessPlugin = $this->migratePluginManager - ->createInstance('migration', $migration_plugin_configuration, $migration); - - $executable = new MigrateExecutable($migration, new MigrateMessage()); - - $roles = []; - foreach ($source_roles as $role) { - $roles[] = $migrationProcessPlugin->transform($role, $executable, $row, NULL); - } - return array_combine($roles, $roles); - } - } diff --git a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php index b9e7b5f..9ba852c 100644 --- a/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php +++ b/core/modules/field/src/Plugin/migrate/process/d6/FieldInstanceSettings.php @@ -64,7 +64,6 @@ public function transform($value, MigrateExecutableInterface $migrate_executable ->transformFieldInstanceSettings($row); } catch (PluginNotFoundException $e) { - } list($widget_type, $widget_settings, $field_settings) = $value; @@ -76,7 +75,6 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $settings['prefix'] = $field_settings['prefix']; $settings['suffix'] = $field_settings['suffix']; break; - } return $settings; } diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php index d6577f1..7e8f23e 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldInstanceTest.php @@ -117,7 +117,7 @@ public function testFieldInstanceMigration() { ]; $this->assertIdentical($expected, $field->getSetting('handler_settings')); - // Test node reference to entity reference migration. + // Test user reference to entity reference migration. $field = FieldConfig::load('node.story.field_user_reference'); $this->assertIdentical('User reference', $field->label()); $this->assertIdentical('default:user', $field->getSetting('handler')); @@ -130,7 +130,7 @@ public function testFieldInstanceMigration() { ]; $this->assertIdentical($expected, $field->getSetting('handler_settings')); - // Test node reference to entity reference migration. + // Test user reference to entity reference migration. $field = FieldConfig::load('node.story.field_user_reference_2'); $this->assertIdentical('User reference 2', $field->label()); $this->assertIdentical('default:user', $field->getSetting('handler')); diff --git a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php index 2a13664..a905d7d 100644 --- a/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php +++ b/core/modules/field/tests/src/Kernel/Migrate/d6/MigrateFieldWidgetSettingsTest.php @@ -30,7 +30,6 @@ public function testWidgetSettings() { // Text field. $component = $form_display->getComponent('field_test'); - $expected = []; $expected = array('weight' => 1, 'type' => 'text_textfield'); $expected['settings'] = array('size' => 60, 'placeholder' => ''); $expected['third_party_settings'] = []; diff --git a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php index 3df2735..d7fd610 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/d6/FileField.php @@ -59,7 +59,6 @@ public function getFieldType(Row $row) { /** * {@inheritdoc} */ - public function transformFieldInstanceSettings(Row $row) { $widget_type = $row->getSourceProperty('widget_type'); $widget_settings = $row->getSourceProperty('widget_settings'); diff --git a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php index 4b50882..1d62c7d 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php @@ -53,7 +53,7 @@ public function transformFieldInstanceSettings(Row $row) { $field_settings = $row->getSourceProperty('global_settings'); // D6 has optional, required, value and none. D8 only has disabled (0) // optional (1) and required (2). - $map = array('disabled' => 0, 'optional' => 1, 'required' => 2); + $map = ['disabled' => 0, 'optional' => 1, 'required' => 2]; $settings['title'] = $map[$field_settings['title']]; return $settings; } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php index b939ffb..632f0c9 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php @@ -4,7 +4,6 @@ use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Plugin\MigrationInterface; -use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface;