diff --git a/paragraphs.module b/paragraphs.module index cfd0fc6..180f824 100644 --- a/paragraphs.module +++ b/paragraphs.module @@ -436,3 +436,11 @@ function paragraphs_library_info_alter(&$libraries, $extension) { return $libraries; } + +/** + * Implements hook_migration_plugins_alter(). + */ +function paragraphs_migration_plugins_alter(array &$migrations) { + $migrations['d7_field_instance']['migration_dependancies']['optional'][] = 'd7_field_collection_type'; + $migrations['d7_field_instance']['migration_dependancies']['optional'][] = 'd7_paragraph_type'; +} diff --git a/src/Plugin/migrate/field/Paragraphs.php b/src/Plugin/migrate/field/Paragraphs.php index 76992bd..a9d588e 100644 --- a/src/Plugin/migrate/field/Paragraphs.php +++ b/src/Plugin/migrate/field/Paragraphs.php @@ -23,9 +23,16 @@ class Paragraphs extends FieldPluginBase { * {@inheritdoc} */ public function processField(MigrationInterface $migration) { + $paragraph_field_settings = [ - 'paragraphs' => [ - 'plugin' => 'paragraphs_field_settings', + 'process' => [ + 'plugin' => 'static_map', + 'source' => 'type', + 'map' => [ + 'field_collection' => 'paragraph', + 'paragraphs' => 'paragraph', + ], + 'default_value' => NULL, ], ]; @@ -38,14 +45,46 @@ class Paragraphs extends FieldPluginBase { // paragraph entity properly. I don't know what the point of that would // be, but there may be a better place to put this. $paragraphs_entity_type = [ + 'paragraphs_process' => [ + 'plugin' => 'static_map', + 'source' => 'entity_type', + 'map' => [ + 'field_collection_item' => 'paragraph', + 'paragraphs_item' => 'paragraph', + ], + 'bypass' => TRUE, + ], + ]; + + $migration->setProcessOfProperty('settings/target_type', $paragraph_field_settings); + $migration->mergeProcessOfProperty('entity_type', $paragraphs_entity_type); + } + + /** + * {@inheritdoc} + */ + public function processFieldInstance(MigrationInterface $migration) { + $paragraphs_entity_type = [ + 'paragraphs' => [ + 'plugin' => 'static_map', + 'source' => 'entity_type', + 'map' => [ + 'field_collection_item' => 'paragraph', + 'paragraphs_item' => 'paragraph', + ], + 'bypass' => TRUE, + ], + ]; + + $field_collection_bundle = [ 'paragraphs' => [ - 'plugin' => 'paragraphs_entity_type', + 'plugin' => 'field_collection_bundle', + 'prefix' => 'field_', ], ]; - $migration->MergeProcessOfProperty('settings', $paragraph_field_settings); - $migration->MergeProcessOfProperty('entity_type', $paragraphs_entity_type); - $test = 'test'; + $migration->mergeProcessOfProperty('entity_type', $paragraphs_entity_type); + $migration->mergeProcessOfProperty('bundle', $field_collection_bundle); } } diff --git a/src/Plugin/migrate/process/ParagraphsEntityType.php b/src/Plugin/migrate/process/FieldCollectionBundle.php similarity index 51% rename from src/Plugin/migrate/process/ParagraphsEntityType.php rename to src/Plugin/migrate/process/FieldCollectionBundle.php index 2161caf..0be31ab 100644 --- a/src/Plugin/migrate/process/ParagraphsEntityType.php +++ b/src/Plugin/migrate/process/FieldCollectionBundle.php @@ -7,22 +7,26 @@ use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\Row; /** - * Class ParagraphsEntityType. + * Process the Field Collection Bundle id. * * @see \Drupal\migrate\Plugin\MigrateProcessInterface * * @MigrateProcessPlugin( - * id = "paragraphs_entity_type" + * id = "field_collection_bundle" * ) */ -class ParagraphsEntityType extends ProcessPluginBase { +class FieldCollectionBundle extends ProcessPluginBase { /** * {@inheritdoc} */ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { - if ($value == 'field_collection_item' || $value == 'paragraphs_item') { - $value = 'paragraph'; + if ($row->getSourceProperty('entity_type') == 'field_collection_item') { + // Remove prefix if it is set in configs. + $prefix = $this->configuration['prefix']; + if (isset($prefix) && strpos($value, $prefix) === 0) { + $value = substr($value, strlen($prefix)); + } } return $value; } diff --git a/src/Plugin/migrate/process/ParagraphsFieldSettings.php b/src/Plugin/migrate/process/ParagraphsFieldSettings.php deleted file mode 100644 index 4ac81d1..0000000 --- a/src/Plugin/migrate/process/ParagraphsFieldSettings.php +++ /dev/null @@ -1,31 +0,0 @@ -getSourceProperty('type'); - if ($field_type == 'field_collection' || $field_type == 'paragraphs') { - $value['target_type'] = 'paragraph'; - } - return $value; - } - -}