Issue #3199578 by quietone, danflanagan8, huzooka: Fix EntityReferenceTranslationDeriver process pipeline

merge-requests/1067/merge
Alex Pott 2021-10-18 10:29:44 +01:00
parent 0acc2f337c
commit 1f019ab9d8
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
5 changed files with 58 additions and 13 deletions

View File

@ -153,7 +153,7 @@ class EntityReferenceTranslationDeriver extends DeriverBase implements Container
'plugin' => 'sub_process',
'source' => $field_name,
'process' => [
'target_id' => [
'translation_target_id' => [
[
'plugin' => 'migration_lookup',
'source' => 'target_id',
@ -162,13 +162,22 @@ class EntityReferenceTranslationDeriver extends DeriverBase implements Container
],
[
'plugin' => 'skip_on_empty',
'method' => 'row',
'method' => 'process',
],
[
'plugin' => 'extract',
'index' => [0],
],
],
'target_id' => [
[
'plugin' => 'null_coalesce',
'source' => [
'@translation_target_id',
'target_id',
],
],
],
],
];

View File

@ -4,7 +4,7 @@
* @file
* A database agnostic dump for testing purposes.
*
* This file was generated by the Drupal 8.0 db-tools.php script.
* This file was generated by the Drupal 9.3.0-dev db-tools.php script.
*/
use Drupal\Core\Database\Database;
@ -4312,7 +4312,7 @@ $connection->insert('field_config')
'storage_module' => 'field_sql_storage',
'storage_active' => '1',
'locked' => '0',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:11:"target_type";s:4:"node";s:7:"handler";s:4:"base";s:16:"handler_settings";a:2:{s:14:"target_bundles";a:1:{s:7:"article";s:7:"article";}s:4:"sort";a:1:{s:4:"type";s:4:"none";}}}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:28:"field_data_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:32:"field_revision_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}}}}s:12:"foreign keys";a:1:{s:4:"node";a:2:{s:5:"table";s:4:"node";s:7:"columns";a:1:{s:9:"target_id";s:3:"nid";}}}s:7:"indexes";a:1:{s:9:"target_id";a:1:{i:0;s:9:"target_id";}}s:2:"id";s:2:"39";}',
'data' => 'a:7:{s:12:"translatable";s:1:"0";s:12:"entity_types";a:0:{}s:8:"settings";a:3:{s:11:"target_type";s:4:"node";s:7:"handler";s:4:"base";s:16:"handler_settings";a:2:{s:14:"target_bundles";a:2:{s:7:"article";s:7:"article";s:5:"forum";s:5:"forum";}s:4:"sort";a:1:{s:4:"type";s:4:"none";}}}s:7:"storage";a:5:{s:4:"type";s:17:"field_sql_storage";s:8:"settings";a:0:{}s:6:"module";s:17:"field_sql_storage";s:6:"active";s:1:"1";s:7:"details";a:1:{s:3:"sql";a:2:{s:18:"FIELD_LOAD_CURRENT";a:1:{s:28:"field_data_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}s:19:"FIELD_LOAD_REVISION";a:1:{s:32:"field_revision_field_reference_2";a:1:{s:9:"target_id";s:27:"field_reference_2_target_id";}}}}}s:12:"foreign keys";a:1:{s:4:"node";a:2:{s:5:"table";s:4:"node";s:7:"columns";a:1:{s:9:"target_id";s:3:"nid";}}}s:7:"indexes";a:1:{s:9:"target_id";a:1:{i:0;s:9:"target_id";}}s:2:"id";s:2:"39";}',
'cardinality' => '1',
'translatable' => '0',
'deleted' => '0',
@ -8181,7 +8181,7 @@ $connection->insert('field_data_field_node_reference')
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '2',
'revision_id' => '11',
'language' => 'und',
'delta' => '0',
'field_node_reference_nid' => '5',
@ -8768,7 +8768,7 @@ $connection->insert('field_data_field_reference_2')
'revision_id' => '11',
'language' => 'und',
'delta' => '0',
'field_reference_2_target_id' => '5',
'field_reference_2_target_id' => '6',
))
->values(array(
'entity_type' => 'node',
@ -14731,6 +14731,16 @@ $connection->insert('field_revision_field_node_reference')
'delta' => '0',
'field_node_reference_nid' => '5',
))
->values(array(
'entity_type' => 'node',
'bundle' => 'article',
'deleted' => '0',
'entity_id' => '2',
'revision_id' => '11',
'language' => 'und',
'delta' => '0',
'field_node_reference_nid' => '5',
))
->execute();
$connection->schema()->createTable('field_revision_field_phone', array(
'fields' => array(
@ -15378,7 +15388,7 @@ $connection->insert('field_revision_field_reference_2')
'revision_id' => '11',
'language' => 'und',
'delta' => '0',
'field_reference_2_target_id' => '5',
'field_reference_2_target_id' => '6',
))
->values(array(
'entity_type' => 'node',

View File

@ -51,8 +51,6 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
'language',
'd7_language_content_settings',
'd7_taxonomy_vocabulary',
'd7_node',
'd7_node_translation',
]);
}
@ -70,12 +68,16 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
/**
* Tests entity reference translations.
*
* @dataProvider providerTestEntityReferenceTranslations
*/
public function testEntityReferenceTranslations() {
public function testEntityReferenceTranslations($node_migrations) {
$this->executeMigrations($node_migrations);
// Test the entity reference field before the follow-up migrations.
$node = Node::load(2);
$this->assertSame('5', $node->get('field_reference')->target_id);
$this->assertSame('5', $node->get('field_reference_2')->target_id);
$this->assertSame('6', $node->get('field_reference_2')->target_id);
$translation = $node->getTranslation('is');
$this->assertSame('4', $translation->get('field_reference')->target_id);
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
@ -99,7 +101,7 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
// Test the entity reference field after the follow-up migrations.
$node = Node::load(2);
$this->assertSame('4', $node->get('field_reference')->target_id);
$this->assertSame('4', $node->get('field_reference_2')->target_id);
$this->assertSame('6', $node->get('field_reference_2')->target_id);
$translation = $node->getTranslation('is');
$this->assertSame('4', $translation->get('field_reference')->target_id);
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
@ -115,4 +117,18 @@ class FollowUpMigrationsTest extends MigrateDrupal7TestBase {
$this->assertSame('2', $user->get('field_reference')->target_id);
}
/**
* Data provider for testEntityReferenceTranslations().
*/
public function providerTestEntityReferenceTranslations() {
return [
[
['d7_node', 'd7_node_translation'],
],
[
['d7_node_complete'],
],
];
}
}

View File

@ -237,7 +237,7 @@ class Upgrade7Test extends MigrateUpgradeExecuteTestBase {
protected function assertFollowUpMigrationResults() {
$node = Node::load(2);
$this->assertSame('4', $node->get('field_reference')->target_id);
$this->assertSame('4', $node->get('field_reference_2')->target_id);
$this->assertSame('6', $node->get('field_reference_2')->target_id);
$translation = $node->getTranslation('is');
$this->assertSame('4', $translation->get('field_reference')->target_id);
$this->assertSame('4', $translation->get('field_reference_2')->target_id);

View File

@ -4,6 +4,7 @@ namespace Drupal\Tests\node\Kernel\Migrate\d7;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\NodeMigrateType;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
use Drupal\Tests\file\Kernel\Migrate\d7\FileMigrationSetupTrait;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
@ -136,6 +137,15 @@ class MigrateNodeCompleteTest extends MigrateDrupal7TestBase {
$this->assertSame('Bob', $revision->field_user_reference[0]->entity->getAccountName());
}
// Test the translated node reference in the latest revision of node 2. This
// references the legacy site node 4 instead of node 2. The reference is
// fixed by the followup migrations, 'd7_entity_reference_translation' and
// tested in \Drupal\Tests\migrate_drupal\Kernel\d7\FollowUpMigrationsTest.
$node = Node::load(2);
$this->assertSame('6', $node->get('field_reference_2')->target_id);
$translation = $node->getTranslation('is');
$this->assertSame('4', $translation->get('field_reference_2')->target_id);
// Test the order in multi-value fields.
$revision = $this->nodeStorage->loadRevision(1);
$this->assertSame([