Created
December 12, 2023 14:16
-
-
Save junaidpv/50eee2929600f52db27b2c5c968a54db to your computer and use it in GitHub Desktop.
Migrate field collections with same ID and revision IDs as D7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/migrations/d7_field_collection.yml b/migrations/d7_field_collection.yml | |
index a7077d3..4c9be52 100644 | |
--- a/migrations/d7_field_collection.yml | |
+++ b/migrations/d7_field_collection.yml | |
@@ -8,6 +8,8 @@ deriver: Drupal\paragraphs\Plugin\migrate\D7FieldCollectionItemDeriver | |
source: | |
plugin: d7_field_collection_item | |
process: | |
+ id: item_id | |
+ revision_id: revision_id | |
type: bundle | |
# @todo Get the langcode from the parent entity. | |
# See https://drupal.org/i/3146632. | |
diff --git a/migrations/d7_field_collection_revisions.yml b/migrations/d7_field_collection_revisions.yml | |
index 01ca0e3..2762f41 100644 | |
--- a/migrations/d7_field_collection_revisions.yml | |
+++ b/migrations/d7_field_collection_revisions.yml | |
@@ -4,20 +4,12 @@ migration_tags: | |
- Drupal 7 | |
- Content | |
- Field Collection Revisions Content | |
-deriver: Drupal\paragraphs\Plugin\migrate\D7FieldCollectionItemDeriver | |
+deriver: Drupal\paragraphs\Plugin\migrate\D7FieldCollectionItemRevisionDeriver | |
source: | |
plugin: d7_field_collection_item_revision | |
process: | |
- id: | |
- - | |
- plugin: paragraphs_lookup | |
- tags: | |
- - Field Collection Content | |
- source: item_id | |
- - | |
- plugin: extract | |
- index: | |
- - id | |
+ id: item_id | |
+ revision_id: revision_id | |
type: bundle | |
# @todo Get the langcode from the parent entity revision. | |
# See https://drupal.org/i/3146632. | |
@@ -25,6 +17,3 @@ process: | |
destination: | |
plugin: entity_reference_revisions:paragraph | |
new_revisions: TRUE | |
-migration_dependencies: | |
- required: | |
- - d7_field_collection | |
diff --git a/src/Plugin/migrate/D7FieldCollectionItemRevisionDeriver.php b/src/Plugin/migrate/D7FieldCollectionItemRevisionDeriver.php | |
new file mode 100644 | |
index 0000000..ac747b9 | |
--- /dev/null | |
+++ b/src/Plugin/migrate/D7FieldCollectionItemRevisionDeriver.php | |
@@ -0,0 +1,32 @@ | |
+<?php | |
+ | |
+namespace Drupal\paragraphs\Plugin\migrate; | |
+ | |
+use Drupal\Component\Plugin\Derivative\DeriverBase; | |
+use Drupal\Core\Database\DatabaseExceptionWrapper; | |
+use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; | |
+use Drupal\Core\StringTranslation\StringTranslationTrait; | |
+use Drupal\migrate\Exception\RequirementsException; | |
+use Drupal\migrate\Plugin\MigrationDeriverTrait; | |
+use Drupal\migrate_drupal\FieldDiscoveryInterface; | |
+use Symfony\Component\DependencyInjection\ContainerInterface; | |
+ | |
+/** | |
+ * Deriver for field collections. | |
+ */ | |
+class D7FieldCollectionItemRevisionDeriver extends D7FieldCollectionItemDeriver { | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function getDerivativeDefinitions($base_plugin_definition) { | |
+ $derivatives = parent::getDerivativeDefinitions($base_plugin_definition); | |
+ | |
+ foreach ($derivatives as &$derivative) { | |
+ $derivative['migration_dependencies']['required'][] = 'd7_field_collection:' . $derivative['destination']['default_bundle']; | |
+ } | |
+ // "d7_field_collection:deferred_fees" | |
+ return $derivatives; | |
+ } | |
+ | |
+} | |
diff --git a/src/Plugin/migrate/field/FieldCollection.php b/src/Plugin/migrate/field/FieldCollection.php | |
index 73d8b00..f511a0c 100644 | |
--- a/src/Plugin/migrate/field/FieldCollection.php | |
+++ b/src/Plugin/migrate/field/FieldCollection.php | |
@@ -71,8 +71,9 @@ class FieldCollection extends FieldPluginBase { | |
$dependencies = $migration->getMigrationDependencies() + ['required' => []]; | |
$dependencies['required'] = array_unique(array_merge(array_values($dependencies['required']), [$migration_dependency])); | |
$migration->set('migration_dependencies', $dependencies); | |
- | |
- if (strpos($migration->getDestinationPlugin()->getPluginId(), 'entity_revision:') === 0 || strpos($migration->getDestinationPlugin()->getPluginId(), 'entity_complete:') === 0) { | |
+ if (strpos($migration->getDestinationPlugin()->getPluginId(), 'entity_revision:') === 0 || | |
+ strpos($migration->getDestinationPlugin()->getPluginId(), 'entity_complete:') === 0 || | |
+ strpos($migration->getDestinationPlugin()->getPluginId(), 'entity_reference_revisions:') === 0) { | |
$dependencies['required'] = array_unique(array_merge(array_values($dependencies['required']), [$migration_rev_dependency])); | |
$migration->set('migration_dependencies', $dependencies); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment