Loading core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php +37 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,43 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $instance_settings['handler_settings'] = $field_settings['handler_settings']; } if ($row->getSourceProperty('type') == 'node_reference') { $instance_settings['handler'] = 'default:node'; $instance_settings['handler_settings'] = [ 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'target_bundles' => array_filter($field_data['settings']['referenceable_types'] ?? []), ]; } if ($row->getSourceProperty('type') == 'user_reference') { $instance_settings['handler'] = 'default:user'; $instance_settings['handler_settings'] = [ 'include_anonymous' => TRUE, 'filter' => [ 'type' => '_none', ], 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'auto_create' => FALSE, ]; if ($row->hasSourceProperty('roles')) { $instance_settings['handler_settings']['filter']['type'] = 'role'; foreach ($row->get('roles') as $role) { $instance_settings['handler_settings']['filter']['role'] = [ $role['name'] => $role['name'], ]; } } } // Get the labels for the list_boolean type. if ($row->getSourceProperty('type') === 'list_boolean') { if (isset($field_data['settings']['allowed_values'][1])) { Loading core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php +4 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,10 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $value['target_type'] = 'taxonomy_term'; break; case 'user_reference': $value['target_type'] = 'user'; break; default: break; } Loading core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +11 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,17 @@ public function prepareRow(Row $row) { } } // Get the user roles for user reference fields. if ($row->getSourceProperty('type') == 'user_reference') { $data = unserialize($field_definition['data']); if (!empty($data['settings']['referenceable_roles'])) { $rid = $data['settings']['referenceable_roles']; $query = $this->select('role', 'r')->fields('r') ->condition('rid', $rid, 'IN'); $results = $query->execute()->fetchAll(); $row->setSourceProperty('roles', $results); } } return parent::prepareRow($row); } Loading core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,27 @@ public function testFieldInstances() { $this->assertEntity('node.article.field_vocab_localize', 'vocab_localize', 'entity_reference', FALSE, FALSE); $this->assertEntity('node.article.field_vocab_translate', 'vocab_translate', 'entity_reference', FALSE, TRUE); // Test the node and user reference fields. $this->assertEntity('node.article.field_node_reference', 'Node Reference', 'entity_reference', FALSE, TRUE); $this->assertEntity('node.article.field_user_reference', 'User Reference', 'entity_reference', FALSE, TRUE); $expected_handler_settings = [ 'include_anonymous' => TRUE, 'filter' => [ 'type' => 'role', 'role' => [ 'authenticated user' => 'authenticated user', ], ], 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'auto_create' => FALSE, ]; $field = FieldConfig::load('node.article.field_user_reference'); $actual = $field->getSetting('handler_settings'); $this->assertSame($expected_handler_settings, $actual); // Test migration of text field instances with different text processing. // All text and text_long field instances using a field base that has only // plain text instances should be migrated to string and string_long fields. Loading core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -143,6 +143,12 @@ public function testFields() { $field = FieldStorageConfig::load('node.field_date_with_end_time'); $this->assertNull($field->getSetting('datetime_type')); // Assert node and user reference fields. $field = FieldStorageConfig::load('node.field_node_reference'); $this->assertEquals('node', $field->getSetting('target_type')); $field = FieldStorageConfig::load('node.field_user_reference'); $this->assertEquals('user', $field->getSetting('target_type')); // Test the migration of text fields with different text processing. // All text and text_long field bases that have only plain text instances // should be migrated to string and string_long fields. Loading Loading
core/modules/field/src/Plugin/migrate/process/d7/FieldInstanceSettings.php +37 −0 Original line number Diff line number Diff line Loading @@ -65,6 +65,43 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $instance_settings['handler_settings'] = $field_settings['handler_settings']; } if ($row->getSourceProperty('type') == 'node_reference') { $instance_settings['handler'] = 'default:node'; $instance_settings['handler_settings'] = [ 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'target_bundles' => array_filter($field_data['settings']['referenceable_types'] ?? []), ]; } if ($row->getSourceProperty('type') == 'user_reference') { $instance_settings['handler'] = 'default:user'; $instance_settings['handler_settings'] = [ 'include_anonymous' => TRUE, 'filter' => [ 'type' => '_none', ], 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'auto_create' => FALSE, ]; if ($row->hasSourceProperty('roles')) { $instance_settings['handler_settings']['filter']['type'] = 'role'; foreach ($row->get('roles') as $role) { $instance_settings['handler_settings']['filter']['role'] = [ $role['name'] => $role['name'], ]; } } } // Get the labels for the list_boolean type. if ($row->getSourceProperty('type') === 'list_boolean') { if (isset($field_data['settings']['allowed_values'][1])) { Loading
core/modules/field/src/Plugin/migrate/process/d7/FieldSettings.php +4 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,10 @@ public function transform($value, MigrateExecutableInterface $migrate_executable $value['target_type'] = 'taxonomy_term'; break; case 'user_reference': $value['target_type'] = 'user'; break; default: break; } Loading
core/modules/field/src/Plugin/migrate/source/d7/FieldInstance.php +11 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,17 @@ public function prepareRow(Row $row) { } } // Get the user roles for user reference fields. if ($row->getSourceProperty('type') == 'user_reference') { $data = unserialize($field_definition['data']); if (!empty($data['settings']['referenceable_roles'])) { $rid = $data['settings']['referenceable_roles']; $query = $this->select('role', 'r')->fields('r') ->condition('rid', $rid, 'IN'); $results = $query->execute()->fetchAll(); $row->setSourceProperty('roles', $results); } } return parent::prepareRow($row); } Loading
core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldInstanceTest.php +21 −0 Original line number Diff line number Diff line Loading @@ -169,6 +169,27 @@ public function testFieldInstances() { $this->assertEntity('node.article.field_vocab_localize', 'vocab_localize', 'entity_reference', FALSE, FALSE); $this->assertEntity('node.article.field_vocab_translate', 'vocab_translate', 'entity_reference', FALSE, TRUE); // Test the node and user reference fields. $this->assertEntity('node.article.field_node_reference', 'Node Reference', 'entity_reference', FALSE, TRUE); $this->assertEntity('node.article.field_user_reference', 'User Reference', 'entity_reference', FALSE, TRUE); $expected_handler_settings = [ 'include_anonymous' => TRUE, 'filter' => [ 'type' => 'role', 'role' => [ 'authenticated user' => 'authenticated user', ], ], 'sort' => [ 'field' => '_none', 'direction' => 'ASC', ], 'auto_create' => FALSE, ]; $field = FieldConfig::load('node.article.field_user_reference'); $actual = $field->getSetting('handler_settings'); $this->assertSame($expected_handler_settings, $actual); // Test migration of text field instances with different text processing. // All text and text_long field instances using a field base that has only // plain text instances should be migrated to string and string_long fields. Loading
core/modules/field/tests/src/Kernel/Migrate/d7/MigrateFieldTest.php +6 −0 Original line number Diff line number Diff line Loading @@ -143,6 +143,12 @@ public function testFields() { $field = FieldStorageConfig::load('node.field_date_with_end_time'); $this->assertNull($field->getSetting('datetime_type')); // Assert node and user reference fields. $field = FieldStorageConfig::load('node.field_node_reference'); $this->assertEquals('node', $field->getSetting('target_type')); $field = FieldStorageConfig::load('node.field_user_reference'); $this->assertEquals('user', $field->getSetting('target_type')); // Test the migration of text fields with different text processing. // All text and text_long field bases that have only plain text instances // should be migrated to string and string_long fields. Loading