diff --git a/src/Plugin/migrate/field/FieldCollection.php b/src/Plugin/migrate/field/FieldCollection.php index 938ece0..f0c8a13 100644 --- a/src/Plugin/migrate/field/FieldCollection.php +++ b/src/Plugin/migrate/field/FieldCollection.php @@ -40,8 +40,17 @@ class FieldCollection extends ParagraphsFieldPluginBase { */ public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) { $process = [ + // The "paragraphs_delta_sort" plugin sorts field values for PostgreSQL + // sources. + // @see \Drupal\paragraphs\Plugin\migrate\process\ParagraphsDeltaSort + // @todo remove when https://drupal.org/i/3164520 is fixed. + [ + 'plugin' => 'paragraphs_delta_sort', + 'source' => $field_name, + ], + ]; + $process[] = [ 'plugin' => 'sub_process', - 'source' => $field_name, 'process' => [ 'target_id' => [ [ diff --git a/src/Plugin/migrate/field/Paragraphs.php b/src/Plugin/migrate/field/Paragraphs.php index dc48412..0bfb99b 100644 --- a/src/Plugin/migrate/field/Paragraphs.php +++ b/src/Plugin/migrate/field/Paragraphs.php @@ -40,8 +40,17 @@ class Paragraphs extends ParagraphsFieldPluginBase { */ public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) { $process = [ + // The "paragraphs_delta_sort" plugin sorts field values for PostgreSQL + // sources. + // @see \Drupal\paragraphs\Plugin\migrate\process\ParagraphsDeltaSort + // @todo remove when https://drupal.org/i/3164520 is fixed. + [ + 'plugin' => 'paragraphs_delta_sort', + 'source' => $field_name, + ], + ]; + $process[] = [ 'plugin' => 'sub_process', - 'source' => $field_name, 'process' => [ 'target_id' => [ [ diff --git a/src/Plugin/migrate/process/ParagraphsDeltaSort.php b/src/Plugin/migrate/process/ParagraphsDeltaSort.php new file mode 100644 index 0000000..6f70372 --- /dev/null +++ b/src/Plugin/migrate/process/ParagraphsDeltaSort.php @@ -0,0 +1,38 @@ + 'Test content type', ], 'node' => [ - 1 => 'A Node', - 2 => 'The thing about Deep Space 9', - 4 => 'is - The thing about Firefly', - 6 => 'Comments are closed :-(', - 7 => 'Comments are open :-)', - 8 => 'Paragraph Migration Test Content UND', - 9 => 'Paragraph Migration Test Content EN', - 11 => 'Content with nested paragraphs ENG', + '1' => 'A Node', + '2' => 'The thing about Deep Space 9', + '4' => 'is - The thing about Firefly', + '6' => 'Comments are closed :-(', + '7' => 'Comments are open :-)', + '8' => 'Paragraph Migration Test Content UND', + '9' => 'Paragraph Migration Test Content EN', + '11' => 'Content with nested paragraphs ENG', ], 'paragraphs_type' => [ 'field_collection_test' => 'Field collection test', @@ -307,28 +309,28 @@ abstract class MigrateUiParagraphsTestBase extends MigrateUpgradeTestBase { // migration. // @see https://www.drupal.org/node/3105503 'paragraph' => [ - 1 => 'Paragraph Migration Test Content UND > Field Collection Test', - 2 => 'Paragraph Migration Test Content UND > Field Collection Test', - 3 => 'Paragraph Migration Test Content EN > Field Collection Test', - 4 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 5 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 6 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 7 => 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', - 8 => 'Paragraph Migration Test Content UND > Nested FC Outer', - 9 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 10 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 11 => 'Content with nested paragraphs ENG > Any Paragraph', - 12 => 'Paragraph Migration Test Content UND > Any Paragraph', - 13 => 'Paragraph Migration Test Content EN > Any Paragraph', - 14 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 15 => 'Paragraph Migration Test Content UND > Any Paragraph', - 16 => 'Paragraph Migration Test Content EN > Any Paragraph', - 17 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 18 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 19 => 'Content with nested paragraphs ENG > Any Paragraph', - 20 => 'Paragraph Migration Test Content UND > Paragraph One Only', - 21 => 'Paragraph Migration Test Content EN > Paragraph One Only', - 22 => 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Paragraph One Only', + 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph', + 'Paragraph Migration Test Content UND > Any Paragraph', + 'Paragraph Migration Test Content UND > Field Collection Test', + 'Paragraph Migration Test Content UND > Field Collection Test', + 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', + 'Paragraph Migration Test Content UND > Paragraph One Only', ], ]; @@ -336,30 +338,30 @@ abstract class MigrateUiParagraphsTestBase extends MigrateUpgradeTestBase { // @todo Should we test the legacy method anyway? if (ParagraphsMigration::getParagraphsMigrationDerivationMethod() === ParagraphsMigration::DERIVATION_STRATEGY_LEGACY) { $expected_entities['paragraph'] = [ - 1 => 'Paragraph Migration Test Content UND > Field Collection Test', - 2 => 'Paragraph Migration Test Content UND > Field Collection Test', - 3 => 'Paragraph Migration Test Content EN > Field Collection Test', - 4 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 5 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 6 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 7 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 8 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 9 => 'Content with nested paragraphs ENG > Any Paragraph', - 10 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 11 => 'Paragraph Migration Test Content UND > Any Paragraph', - 12 => 'Paragraph Migration Test Content UND > Paragraph One Only', - 13 => 'Paragraph Migration Test Content EN > Any Paragraph', - 14 => 'Paragraph Migration Test Content EN > Paragraph One Only', - 15 => 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', - 16 => 'Orphaned Paragraph Bundle One: Nested Paragraph Bundle One ENG with 'The la…', - 17 => 'Paragraph Migration Test Content UND > Any Paragraph', - 18 => 'Paragraph Migration Test Content EN > Any Paragraph', - 19 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 20 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 21 => 'Content with nested paragraphs ENG > Any Paragraph', - 22 => 'Orphaned Paragraph Bundle Two: Nested Paragraph Bundle Two ENG', - 23 => 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', - 24 => 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Orphaned Paragraph Bundle One: Nested Paragraph Bundle One ENG with 'The la…', + 'Orphaned Paragraph Bundle Two: Nested Paragraph Bundle Two ENG', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Paragraph One Only', + 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph', + 'Paragraph Migration Test Content UND > Any Paragraph', + 'Paragraph Migration Test Content UND > Field Collection Test', + 'Paragraph Migration Test Content UND > Field Collection Test', + 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', + 'Paragraph Migration Test Content UND > Paragraph One Only', ]; } @@ -368,58 +370,58 @@ abstract class MigrateUiParagraphsTestBase extends MigrateUpgradeTestBase { // migrated separately. if (Settings::get('migrate_node_migrate_type_classic', FALSE)) { $expected_entities['paragraph'] = [ - 1 => 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', - 2 => 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', - 3 => 'Paragraph Migration Test Content EN > Field Collection Test', - 4 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 5 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 6 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 7 => 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', - 8 => 'Paragraph Migration Test Content UND > Nested FC Outer', - 9 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 10 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 11 => 'Content with nested paragraphs ENG > Any Paragraph', - 12 => 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', - 13 => 'Paragraph Migration Test Content EN > Any Paragraph', - 14 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 15 => 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', - 16 => 'Paragraph Migration Test Content EN > Any Paragraph', - 17 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 18 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 19 => 'Content with nested paragraphs ENG > Any Paragraph', - 20 => 'Paragraph Migration Test Content UND > Paragraph One Only (previous revision)', - 21 => 'Paragraph Migration Test Content EN > Paragraph One Only', - 22 => 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Paragraph One Only', + 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', + 'Paragraph Migration Test Content UND > Paragraph One Only (previous revision)', ]; // The 'legacy' derivation methods ends up in orphaned paragraphs. // @todo Should we test the legacy method anyway? if (ParagraphsMigration::getParagraphsMigrationDerivationMethod() === ParagraphsMigration::DERIVATION_STRATEGY_LEGACY) { $expected_entities['paragraph'] = [ - 1 => 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', - 2 => 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', - 3 => 'Paragraph Migration Test Content EN > Field Collection Test', - 4 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 5 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 6 => 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', - 7 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 8 => 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', - 9 => 'Content with nested paragraphs ENG > Any Paragraph', - 10 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 11 => 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', - 12 => 'Paragraph Migration Test Content UND > Paragraph One Only (previous revision)', - 13 => 'Paragraph Migration Test Content EN > Any Paragraph', - 14 => 'Paragraph Migration Test Content EN > Paragraph One Only', - 15 => 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', - 16 => 'Orphaned Paragraph Bundle One: Nested Paragraph Bundle One ENG with 'The la…', - 17 => 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', - 18 => 'Paragraph Migration Test Content EN > Any Paragraph', - 19 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 20 => 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', - 21 => 'Content with nested paragraphs ENG > Any Paragraph', - 22 => 'Orphaned Paragraph Bundle Two: Nested Paragraph Bundle Two ENG', - 23 => 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', - 24 => 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Content with nested paragraphs ENG > Any Paragraph > Any Paragraph (nested)', + 'Orphaned Paragraph Bundle One: Nested Paragraph Bundle One ENG with 'The la…', + 'Orphaned Paragraph Bundle Two: Nested Paragraph Bundle Two ENG', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content EN > Paragraph One Only', + 'Paragraph Migration Test Content EN > Paragraph One Only (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content UND > Any Paragraph (previous revision)', + 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content UND > Field Collection Test (previous revision)', + 'Paragraph Migration Test Content UND > Nested FC Outer', + 'Paragraph Migration Test Content UND > Nested FC Outer > Nested FC Inner', + 'Paragraph Migration Test Content UND > Paragraph One Only (previous revision)', ]; } } @@ -584,6 +586,14 @@ abstract class MigrateUiParagraphsTestBase extends MigrateUpgradeTestBase { $carry[$entity->id()] = (string) $entity->label(); return $carry; }); + + if (count(array_filter(array_keys($expected_entity_labels), 'is_int')) === count($expected_entity_labels)) { + sort($expected_entity_labels); + $expected_entity_labels = array_values($expected_entity_labels); + sort($actual_labels); + $actual_labels = array_values($actual_labels); + } + $this->assertEquals($expected_entity_labels, $actual_labels, sprintf('The expected %s entities are not matching the actual ones.', $entity_type_id)); } else {