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 65c3756..8cb6198 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php @@ -7,8 +7,11 @@ namespace Drupal\Core\Field\Plugin\migrate\cckfield; +use Drupal\migrate\Entity\Migration; +use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\MigrateExecutable; +use Drupal\migrate\MigrateMessage; use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; /** * @MigrateCckField( @@ -18,9 +21,12 @@ * } * ) */ -class NodeReference extends CckFieldPluginBase { +class NodeReference extends ReferenceBase { - use ReferenceTrait; + /** + * @var string + */ + protected $nodeTypeMigration = 'd6_node_type'; /** * {@inheritdoc} @@ -48,12 +54,59 @@ public function transformFieldStorageSettings(Row $row) { return $settings; } + /** + * {@inheritdoc} + */ + public function processFieldInstance(MigrationInterface $migration) { + parent::processFieldInstance($migration); + + $migration_dependencies = $migration->get('migration_dependencies'); + $migration_dependencies['required'][] = $this->nodeTypeMigration; + $migration->set('migration_dependencies', $migration_dependencies); + } + + /** + * {@inheritdoc} + */ public function transformFieldInstanceSettings(Row $row) { $source_settings = $row->getSourceProperty('global_settings'); $settings['handler'] = 'default:node'; - /** @todo: Use d6_node_tyoe migration for mapping. */ - $settings['handler_settings']['target_bundles'] = $source_settings['referenceable_types']; + $settings['handler_settings']['target_bundles'] = []; + + $node_types = array_filter($source_settings['referenceable_types']); + if (!empty($node_types)) { + $settings['handler_settings']['target_bundles'] = $this->migrateNodeTypes($node_types); + } return $settings; } + /** + * Look up migrated role IDs from the d6_node_type migration. + * + * @param $source_node_types + * The source role IDs. + * + * @return array + * The migrated role IDs. + */ + protected function migrateNodeTypes($source_node_types) { + // Configure the migration process plugin to look up migrated IDs from + // the d6_user_role migration. + $migration_plugin_configuration = [ + 'migration' => $this->nodeTypeMigration, + ]; + + $migration = Migration::create(); + $executable = new MigrateExecutable($migration, new MigrateMessage()); + $row = new Row([], []); + $migrationPlugin = $this->migratePluginManager + ->createInstance('migration', $migration_plugin_configuration, $migration); + + $roles = []; + foreach ($source_node_types as $role) { + $roles[] = $migrationPlugin->transform($role, $executable, $row, NULL); + } + return array_combine($roles, $roles); + } + } diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php new file mode 100644 index 0000000..1104357 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceBase.php @@ -0,0 +1,76 @@ +migratePluginManager = $migration_plugin_manager; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('plugin.manager.migrate.process') + ); + } + + /** + * Gets the name of the field property which holds the entity ID. + * + * @return string + */ + abstract protected function entityId(); + + /** + * {@inheritdoc} + */ + public function getFieldFormatterMap() { + return array(); + } + + /** + * {@inheritdoc} + */ + public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { + $process = array( + 'plugin' => 'iterator', + 'source' => $field_name, + 'process' => array( + 'target_id' => $this->entityId(), + ), + ); + $migration->setProcessOfProperty($field_name, $process); + } + +} diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceTrait.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceTrait.php deleted file mode 100644 index 0b03f20..0000000 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/ReferenceTrait.php +++ /dev/null @@ -1,37 +0,0 @@ - 'iterator', - 'source' => $field_name, - 'process' => array( - 'target_id' => $this->entityId(), - ), - ); - $migration->setProcessOfProperty($field_name, $process); - } - -} 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 e4e064d..ceecefb 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php @@ -7,9 +7,7 @@ namespace Drupal\Core\Field\Plugin\migrate\cckfield; -use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; /** * @MigrateCckField( @@ -19,9 +17,7 @@ * } * ) */ -class TaxonomyTermReference extends CckFieldPluginBase { - - use ReferenceTrait; +class TaxonomyTermReference extends ReferenceBase { /** * {@inheritdoc} diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/UserReference.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/UserReference.php index 80b283f..6d86e00 100644 --- a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/UserReference.php +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/UserReference.php @@ -7,12 +7,14 @@ namespace Drupal\Core\Field\Plugin\migrate\cckfield; +use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\migrate\Entity\Migration; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateMessage; +use Drupal\migrate\Plugin\MigratePluginManager; use Drupal\migrate\Row; -use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @MigrateCckField( @@ -22,9 +24,12 @@ * } * ) */ -class UserReference extends CckFieldPluginBase { +class UserReference extends ReferenceBase { - use ReferenceTrait; + /** + * @var string + */ + protected $userRoleMigration = 'd6_user_role'; /** * {@inheritdoc} @@ -59,7 +64,7 @@ public function processFieldInstance(MigrationInterface $migration) { parent::processFieldInstance($migration); $migration_dependencies = $migration->get('migration_dependencies'); - $migration_dependencies['required'][] = 'd6_user_role'; + $migration_dependencies['required'][] = $this->userRoleMigration; $migration->set('migration_dependencies', $migration_dependencies); } @@ -73,7 +78,6 @@ public function transformFieldInstanceSettings(Row $row) { $settings['handler_settings']['filter']['type'] = '_none'; $settings['handler_settings']['target_bundles'] = NULL; - /** @todo: Use d6_user_role migration for mapping. */ $roles = array_filter($source_settings['referenceable_roles']); if (!empty($roles)) { $settings['handler_settings']['filter']['type'] = 'role'; @@ -96,16 +100,14 @@ protected function migrateUserRoles($source_roles) { // Configure the migration process plugin to look up migrated IDs from // the d6_user_role migration. $migration_plugin_configuration = [ - 'source' => ['id'], - 'migration' => 'd6_user_role', + 'migration' => $this->userRoleMigration, ]; $migration = Migration::create(); $executable = new MigrateExecutable($migration, new MigrateMessage()); $row = new Row([], []); - - $migrationPlugin = \Drupal::service('plugin.manager.migrate.process') - ->createInstance('migration', $migration_plugin_configuration, $migration); + $migrationPlugin = $this->migratePluginManager + ->createInstance('migration',$migration_plugin_configuration, $migration); $roles = []; foreach ($source_roles as $role) { diff --git a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldInstanceTest.php b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldInstanceTest.php index 68ed71e..b6da70a 100644 --- a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldInstanceTest.php +++ b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldInstanceTest.php @@ -97,17 +97,7 @@ public function testFieldInstanceMigration() { $this->assertIdentical('Node reference', $field->label()); $this->assertIdentical('default:node', $field->getSetting('handler')); $expected = [ - 'target_bundles' => [ - 'article' => '0', - 'company' => '0', - 'employee' => '0', - 'test_event' => '0', - 'test_page' => '0', - 'test_planet' => '0', - 'test_story' => '0', - 'sponsor' => '0', - 'story' => '0', - ], + 'target_bundles' => [] ]; $this->assertIdentical($expected, $field->getSetting('handler_settings')); @@ -118,14 +108,6 @@ public function testFieldInstanceMigration() { $expected = [ 'target_bundles' => [ 'article' => 'article', - 'company' => '0', - 'employee' => '0', - 'test_event' => '0', - 'test_page' => '0', - 'test_planet' => '0', - 'test_story' => '0', - 'sponsor' => '0', - 'story' => '0', ], ]; $this->assertIdentical($expected, $field->getSetting('handler_settings')); diff --git a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php b/core/modules/file/src/Plugin/migrate/cckfield/FileField.php index 659f215..0e9a579 100644 --- a/core/modules/file/src/Plugin/migrate/cckfield/FileField.php +++ b/core/modules/file/src/Plugin/migrate/cckfield/FileField.php @@ -62,13 +62,6 @@ public function getFieldType(Row $row) { /** * {@inheritdoc} */ - public function transformFieldStorageSettings(Row $row) { - return parent::transformFieldStorageSettings($row); // TODO: Change the autogenerated stub - } - - /** - * {@inheritdoc} - */ public function transformFieldInstanceSettings(Row $row) { $widget_type = $row->getSourceProperty('widget_type'); $widget_settings = $row->getSourceProperty('widget_settings'); @@ -106,7 +99,7 @@ public function transformFieldInstanceSettings(Row $row) { * as D8 uses "KB" and "MB" respectively. * * @param string $size_string - * The size string, eg 10M + * The size string, e.g. 10M * * @return string * The D8 version of the size string. diff --git a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php index cd9761b..71ba9e9 100644 --- a/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php +++ b/core/modules/link/src/Plugin/migrate/cckfield/LinkField.php @@ -40,18 +40,11 @@ public function getFieldFormatterMap() { * {@inheritdoc} */ public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) { - $process = [ - 'plugin' => 'd6_cck_link', - 'source' => $field_name, - ]; - $migration->mergeProcessOfProperty($field_name, $process); - } - - /** - * {@inheritdoc} - */ - public function transformFieldStorageSettings(Row $row) { - return parent::transformFieldStorageSettings($row); // TODO: Change the autogenerated stub + $process = [ + 'plugin' => 'd6_cck_link', + 'source' => $field_name, + ]; + $migration->mergeProcessOfProperty($field_name, $process); } /** @@ -59,7 +52,6 @@ public function transformFieldStorageSettings(Row $row) { */ public function transformFieldInstanceSettings(Row $row) { $field_settings = $row->getSourceProperty('global_settings'); - // $settings['url'] = $widget_settings['default_value'][0]['url']; // 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);