Issue #2814949 by phenaproxima: Support migration of node reference field values from Drupal 6

8.4.x
Nathaniel Catchpole 2017-05-15 15:23:45 +01:00
parent d0fceeeda9
commit 12ac3a61a2
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,43 @@
<?php
namespace Drupal\migrate_drupal\Plugin\migrate\field;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* @MigrateField(
* id = "nodereference",
* core = {6},
* type_map = {
* "nodereference" = "entity_reference",
* },
* )
*/
class NodeReference 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_node',
'source' => 'nid',
],
],
];
$migration->setProcessOfProperty($field_name, $process);
}
}

View File

@ -89,6 +89,12 @@ class MigrateNodeTest extends MigrateNodeTestBase {
// Test that an email field is migrated.
$this->assertSame('PrincessRuwenne@example.com', $node->field_test_email->value);
// Test that node reference field values were migrated.
$node = Node::load(18);
$this->assertCount(2, $node->field_company);
$this->assertSame('Klingon Empire', $node->field_company[0]->entity->label());
$this->assertSame('Romulan Empire', $node->field_company[1]->entity->label());
$node = Node::load(2);
$this->assertIdentical('Test title rev 3', $node->getTitle());
$this->assertIdentical('test rev 3', $node->body->value);