Issue by phenaproxima: Migrate D6 user reference values to D8

8.4.x
Nathaniel Catchpole 2017-06-20 16:42:42 +01:00
parent 0f37866673
commit e96b787dc4
2 changed files with 47 additions and 0 deletions
core/modules
migrate_drupal/src/Plugin/migrate/field
node/tests/src/Kernel/Migrate/d6

View File

@ -0,0 +1,43 @@
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* @MigrateField(
* id = "userreference",
* core = {6},
* type_map = {
* "userreference" = "entity_reference",
* },
* )
*/
class UserReference extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [];
}
/**
* {@inheritdoc}
*/
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'iterator',
'source' => $field_name,
'process' => [
'target_id' => [
'plugin' => 'migration_lookup',
'migration' => 'd6_user',
'source' => 'uid',
],
],
];
$migration->setProcessOfProperty($field_name, $process);
}
}

View File

@ -95,6 +95,10 @@ class MigrateNodeTest extends MigrateNodeTestBase {
$this->assertSame('Klingon Empire', $node->field_company[0]->entity->label());
$this->assertSame('Romulan Empire', $node->field_company[1]->entity->label());
// Test that user reference field values were migrated.
$this->assertCount(1, $node->field_commander);
$this->assertSame('joe.roe', $node->field_commander[0]->entity->getUsername());
$node = Node::load(2);
$this->assertIdentical('Test title rev 3', $node->getTitle());
$this->assertIdentical('test rev 3', $node->body->value);