0

I'm trying to migrate a D7 field collection to D8 paragraphs, but to a different paragraph bundle type depending on the value in one of the field collection's fields.

The logic is as follows: If the field collection's field_type value is "header", the migration should create a header paragraph type. If the field collection's field_type value is "card" it should migrate to a card paragraph type.

I'm trying to set a variable in process, and assign the value of that variable to default_bundle in the destination, but it's not working, the paragraph type is empty for the entities created by this migration:

langcode: en
status: true
dependencies: { }
id: d7_field_collection_list_items 
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
 - 'Drupal 7'
migration_group: migrate_drupal_7
label: FC
source:
  plugin: d7_field_collection_item
  key: migrate
  field_name: field_list_item
process:    
  temp_bundle_type:
    plugin: static_map
    source: field_list_item_type
    map:            
      card: card
      header: header
    default_value: card 
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: '@temp_bundle_type'
migration_dependencies:
  required: { }
  optional: { }

What is the correct way to achieve what I am trying to do? I have tried several other methods without success.

2 Answers 2

1

Don't use the default_bundle at all, instead set the bundle type like other field values in the process section:

process:    
  temp_bundle_type:
    plugin: static_map
    source: field_list_item_type
    map:            
      card: card
      header: header
    default_value: card 
  type: '@temp_bundle_type'
3
  • Yes! This is exactly the right approach, thank you so much @Hudri! Today, you are my best friend, kind stranger on the internet!
    – ryrye
    Commented Jun 12, 2019 at 17:21
  • I should mention that I'm getting the following warning: reset() expects parameter 1 to be array, string given ContentEntityStorageBase.php:121 - not sure what's the cause, but everything seems to be working nonetheless.
    – ryrye
    Commented Jun 12, 2019 at 18:10
  • .. and I have to run the migration twice to get the fields to show up properly. This is likely unrelated to the solution above, and just some misconfiguration on my end.
    – ryrye
    Commented Jun 12, 2019 at 18:51
0

If we want to migrate field collection to paragraphs first you should create paragraph types and it's fields manually. There is no automation available yet to create paragraph types.

After that you can write migration script in .yml format to migrate content.

Reference(Migrating data from a SQL source): https://www.mtech-llc.com/blog/ada-hernandez/migration-field-collection-d7-paragraphs-node-d8

Example of Migrating data from a CSV source:

id: d7_field_collection_list_items 
migration_group: migrate_drupal_7
label: 'Import field collection to paragraph'
source:
  plugin: csv
  path: 'csv file path'
process:
  type:
    plugin: default_value
    default_value: 'paragraph type name'
  // Do field mapping here.
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: 'paragraph type name'
migration_dependencies: {  }
1
  • Thanks, but yes, all that is clear, and I've already done it. The question here is how to migrate variably to one paragraph type OR another, depending on a criteria in the source.
    – ryrye
    Commented Jun 12, 2019 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.