diff --git a/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php new file mode 100644 index 0000000..9ef9172 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/NodeReference.php @@ -0,0 +1,38 @@ + '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 new file mode 100644 index 0000000..f30ee38 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/migrate/cckfield/TaxonomyTermReference.php @@ -0,0 +1,38 @@ +cckPluginManager = $cck_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.cckfield') + ); + } + + /** + * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - list($field_type, $global_settings) = $value; - return $this->getSettings($field_type, $global_settings); + list($field_type, $global_settings, $source_field_type) = $value; + $settings = $this->getSettings($field_type, $global_settings); + + try { + $plugin = $this->cckPluginManager->createInstance($source_field_type); + + // @todo: Implement transformFieldStorageSettings in every MigrateCckField + // plugin. + if ($plugin && method_exists($plugin, 'transformFieldStorageSettings')) { + $settings = $plugin->transformFieldStorageSettings($value, $migrate_executable, $row, $destination_property); + } + } + catch (PluginNotFoundException $e) { + // @todo: Nothing? + } + + return $settings; } /** @@ -40,6 +93,8 @@ public function transform($value, MigrateExecutableInterface $migrate_executable * * @return array * A valid array of settings. + * + * @deprecated Move migrations to the related MigrateCckField plugins. */ public function getSettings($field_type, $global_settings) { $max_length = isset($global_settings['max_length']) ? $global_settings['max_length'] : ''; diff --git a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php index 1eb5ad6..e663f74 100644 --- a/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php +++ b/core/modules/field/src/Tests/Migrate/d6/MigrateFieldTest.php @@ -96,6 +96,16 @@ public function testFields() { $field_storage = FieldStorageConfig::load('node.field_test_text_single_checkbox'); $this->assertIdentical("boolean", $field_storage->getType(), t('Field type is @fieldtype. It should be boolean.', array('@fieldtype' => $field_storage->getType()))); + // Node reference to entity reference migration. + $field_storage = FieldStorageConfig::load('node.field_node_reference'); + $this->assertIdentical('entity_reference', $field_storage->getType()); + $this->assertIdentical('node', $field_storage->getSetting('target_type')); + + // User reference to entity reference migration. + $field_storage = FieldStorageConfig::load('node.field_user_reference'); + $this->assertIdentical('entity_reference', $field_storage->getType()); + $this->assertIdentical('user', $field_storage->getSetting('target_type')); + // Validate that the source count and processed count match up. /** @var \Drupal\migrate\Entity\MigrationInterface $migration */ $migration = Migration::load('d6_field'); diff --git a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php index dbe499d..31342c9 100644 --- a/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php +++ b/core/modules/migrate_drupal/src/Plugin/MigrateCckFieldInterface.php @@ -9,6 +9,7 @@ use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; /** @@ -89,4 +90,15 @@ public function processCckFieldValues(MigrationInterface $migration, $field_name */ public function getFieldType(Row $row); + /** + * Apply any custom transformation to the field storage settings. + * + * @return array + * The destination storage settings. + * + * @see Drupal\field\Plugin\migrate\process\d6\FieldSettings::transform + * @see Drupal\migrate\Plugin\MigrateProcessInterface::transform + */ + public function transformFieldStorageSettings($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property); + } 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 38b96df..18dffec 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/cckfield/CckFieldPluginBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; +use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; use Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface; @@ -85,4 +86,11 @@ public function getFieldType(Row $row) { } } + /** + * {@inheritdoc} + */ + public function transformFieldStorageSettings($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { + return []; + } + } diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal6.php b/core/modules/migrate_drupal/tests/fixtures/drupal6.php index 0f60343..6360f38 100644 --- a/core/modules/migrate_drupal/tests/fixtures/drupal6.php +++ b/core/modules/migrate_drupal/tests/fixtures/drupal6.php @@ -1998,6 +1998,90 @@ )) ->execute(); +$connection->schema()->createTable('content_field_node_reference', array( + 'fields' => array( + 'vid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'nid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'field_node_reference_nid' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + ), + 'primary key' => array( + 'vid', + 'delta', + ), + 'indexes' => array( + 'nid' => array( + 'nid', + ), + 'field_node_reference_nid' => array( + 'field_node_reference_nid', + ), + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('content_field_node_reference') +->fields(array( + 'vid', + 'nid', + 'delta', + 'field_node_reference_nid', +)) +->values(array( + 'vid' => '1', + 'nid' => '1', + 'delta' => '0', + 'field_node_reference_nid' => 2, +)) +->values(array( + 'vid' => '2', + 'nid' => '1', + 'delta' => '0', + 'field_node_reference_nid' => NULL, +)) +->values(array( + 'vid' => '3', + 'nid' => '2', + 'delta' => '0', + 'field_node_reference_nid' => NULL, +)) +->values(array( + 'vid' => '5', + 'nid' => '2', + 'delta' => '0', + 'field_node_reference_nid' => NULL, +)) +->values(array( + 'vid' => '12', + 'nid' => '9', + 'delta' => '0', + 'field_node_reference_nid' => NULL, +)) +->execute(); + $connection->schema()->createTable('content_field_test', array( 'fields' => array( 'vid' => array( @@ -2228,6 +2312,90 @@ )) ->execute(); +$connection->schema()->createTable('content_field_user_reference', array( + 'fields' => array( + 'vid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'nid' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'delta' => array( + 'type' => 'int', + 'not null' => TRUE, + 'size' => 'normal', + 'default' => '0', + 'unsigned' => TRUE, + ), + 'field_user_reference_uid' => array( + 'type' => 'int', + 'not null' => FALSE, + 'size' => 'normal', + 'unsigned' => TRUE, + ), + ), + 'primary key' => array( + 'vid', + 'delta', + ), + 'indexes' => array( + 'nid' => array( + 'nid', + ), + 'field_user_reference_uid' => array( + 'field_user_reference_uid', + ), + ), + 'mysql_character_set' => 'utf8', +)); + +$connection->insert('content_field_user_reference') +->fields(array( + 'vid', + 'nid', + 'delta', + 'field_user_reference_uid', +)) +->values(array( + 'vid' => '1', + 'nid' => '1', + 'delta' => '0', + 'field_user_reference_uid' => NULL, +)) +->values(array( + 'vid' => '2', + 'nid' => '1', + 'delta' => '0', + 'field_user_reference_uid' => NULL, +)) +->values(array( + 'vid' => '3', + 'nid' => '2', + 'delta' => '0', + 'field_user_reference_uid' => NULL, +)) +->values(array( + 'vid' => '5', + 'nid' => '2', + 'delta' => '0', + 'field_user_reference_uid' => NULL, +)) +->values(array( + 'vid' => '12', + 'nid' => '9', + 'delta' => '0', + 'field_user_reference_uid' => NULL, +)) +->execute(); + $connection->schema()->createTable('content_group', array( 'fields' => array( 'group_type' => array( @@ -2395,6 +2563,18 @@ 'locked' => '0', )) ->values(array( + 'field_name' => 'field_node_reference', + 'type' => 'nodereference', + 'global_settings' => 'a:1:{s:19:"referenceable_types";a:9:{s:7:"article";i:0;s:7:"company";i:0;s:8:"employee";i:0;s:10:"test_event";i:0;s:9:"test_page";i:0;s:11:"test_planet";i:0;s:10:"test_story";i:0;s:7:"sponsor";i:0;s:5:"story";i:0;}}', + 'required' => '0', + 'multiple' => '1', + 'db_storage' => '0', + 'module' => 'nodereference', + 'db_columns' => 'a:1:{s:3:"nid";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:0;s:5:"index";b:1;}}', + 'active' => '1', + 'locked' => '0', +)) +->values(array( 'field_name' => 'field_test', 'type' => 'text', 'global_settings' => 'a:4:{s:15:"text_processing";s:1:"1";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}', @@ -2634,6 +2814,18 @@ 'active' => '1', 'locked' => '0', )) +->values(array( + 'field_name' => 'field_user_reference', + 'type' => 'userreference', + 'global_settings' => 'a:2:{s:19:"referenceable_roles";a:4:{i:2;i:0;i:3;i:0;i:4;i:0;i:5;i:0;}s:20:"referenceable_status";s:0:"";}', + 'required' => '0', + 'multiple' => '1', + 'db_storage' => '0', + 'module' => 'userreference', + 'db_columns' => 'a:1:{s:3:"uid";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:0;s:5:"index";b:1;}}', + 'active' => '1', + 'locked' => '0', +)) ->execute(); $connection->schema()->createTable('content_node_field_instance', array( @@ -2729,6 +2921,18 @@ 'widget_active' => '1', )) ->values(array( + 'field_name' => 'field_node_reference', + 'type_name' => 'story', + 'weight' => '21', + 'label' => 'Node reference', + 'widget_type' => 'nodereference_autocomplete', + 'widget_settings' => 'a:4:{s:18:"autocomplete_match";s:8:"contains";s:4:"size";s:2:"60";s:13:"default_value";a:1:{i:0;a:2:{s:3:"nid";N;s:14:"_error_element";s:55:"default_value_widget][field_node_reference][0][nid][nid";}}s:17:"default_value_php";N;}', + 'display_settings' => 'a:5:{s:5:"label";a:2:{s:6:"format";s:5:"above";s:7:"exclude";i:0;}i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', + 'description' => '', + 'widget_module' => 'nodereference', + 'widget_active' => '1', +)) +->values(array( 'field_name' => 'field_test', 'type_name' => 'story', 'weight' => '1', @@ -2992,6 +3196,18 @@ 'widget_module' => 'number', 'widget_active' => '1', )) +->values(array( + 'field_name' => 'field_user_reference', + 'type_name' => 'story', + 'weight' => '20', + 'label' => 'User reference', + 'widget_type' => 'userreference_autocomplete', + 'widget_settings' => 'a:5:{s:18:"autocomplete_match";s:8:"contains";s:4:"size";s:2:"60";s:12:"reverse_link";i:0;s:13:"default_value";a:1:{i:0;a:2:{s:3:"uid";N;s:14:"_error_element";s:55:"default_value_widget][field_user_reference][0][uid][uid";}}s:17:"default_value_php";N;}', + 'display_settings' => 'a:5:{s:5:"label";a:2:{s:6:"format";s:5:"above";s:7:"exclude";i:0;}i:5;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:6:"teaser";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}s:4:"full";a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}i:4;a:2:{s:6:"format";s:7:"default";s:7:"exclude";i:0;}}', + 'description' => '', + 'widget_module' => 'userreference', + 'widget_active' => '1', +)) ->execute(); $connection->schema()->createTable('content_type_page', array(