WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

A working D7 to D8 node migration with paragraphs

Submitted by barnettech on Wed, 01/30/2019 - 09:42

First you need the prepare row functions in your custom module

getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}
function fieldcollection_paragraphs_migration_migrate_upgrade_d7_node_notices_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
  $values = $row->getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}
function fieldcollection_paragraphs_migration_migrate_investor_alert_to_D8_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
  $values = $row->getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}
function fieldcollection_paragraphs_migration_migrate_speech_to_D8_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
  $values = $row->getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}
function fieldcollection_paragraphs_migration_migrate_industry_to_D8_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
  $values = $row->getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}
function fieldcollection_paragraphs_migration_investor_to_D8_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration)
{
  $values = $row->getSourceProperty('field_link_details');
  $value_new = [];
  if ($values) {
    foreach ($values as $value) {
      $value_new[] = ['item_id' => $value['value']];
    }
    $row->setSourceProperty('field_link_details', $value_new);
  }
}

then you have the migration from field collections to paragraphs (this just migrates into paragraphs but doesn't attach them to any of your nodes yet (they haven't even been created yet)

langcode: en
status: true
dependencies: {  }
id: d7_field_collection_link_details
class: null
field_plugin_method: null
cck_plugin_method: null
migration_tags:
  - 'Drupal 7'
migration_group: migrate_drupal_7
label: Related Link Details
source:
  plugin: d7_field_collection_item
  key: d7finnrra
#  field_name is used in our custom plugin to get data about this field_collection_item.
  field_name: field_link_details
process:
  field_link_list_url:
    plugin: iterator
    source: field_link_list_url
    process:
      value: value
    revision_id: revision_id
  field_link_list_teaser:
    plugin: iterator
    source: field_link_list_teaser
    process:
      value: value
    revision_id: revision_id
  field_internal_content_link:
    plugin: iterator
    source: field_internal_content_link
    process:
      uri: value
    revision_id: revision_id
destination:
  plugin: 'entity_reference_revisions:paragraph'
  default_bundle: field_link_details
migration_dependencies:
  required: {  }
  optional: {  }

and now finally you have the node migration referencing in the paragraphs from the previous migration using migration_lookup

source:
  plugin: d7_node
  node_type: investor_alert
  key: d7finnrra
  constants:
    uid_root: 1
    node_article: 'article'
destination:
  plugin: entity:node
  default_bundle: article
process:
  # Hardcode the destination node type (bundle) as 'migrate_example_beer'.
  id: nid
  type:
    plugin: default_value
    default_value: article
  title: title
  body:
    plugin: iterator
    source: body
    process:
      value: value
      format: full_html
  field_core_short_title_tx:
    plugin: get
    source: field_core_short_title_tx
  field_core_pnumber_tx:
    plugin: get
    source: field_core_pnumber_tx
  field_core_cert_cycle_tax:
    plugin: sub_process
    source: field_core_cert_cycle_tax
    process:
      target_id: tid
  field_core_cert_group_tax:
    plugin: sub_process
    source: field_core_cert_group_tax
    process:
      target_id: tid
  field_core_cert_due_dt:
    plugin: iterator
    source: field_core_cert_due_dt
    process:
      value:
        plugin: substr
        source: value
        start: 0
        length: 10
  field_core_content_type_tax:
    plugin: sub_process
    source: field_core_content_type_tax
    process:
      target_id: tid
  field_core_audience_tax:
    plugin: sub_process
    source: field_core_audience_tax
    process:
      target_id: tid
  field_core_invest_veh_tax:
    plugin: sub_process
    source: field_core_invest_veh_tax
    process:
      target_id: tid
  field_core_rule_reg_tax:
    plugin: sub_process
    source: field_core_rule_reg_tax
    process:
      target_id: tid
  field_core_account_type_tax:
    plugin: sub_process
    source: field_core_account_type_tax
    process:
      target_id: tid
  field_core_invest_issue_tax:
    plugin: sub_process
    source: field_core_invest_issue_tax
    process:
      target_id: tid
  field_core_action_tax:
    plugin: sub_process
    source: field_core_action_tax
    process:
      target_id: tid
  field_core_mbr_misconduct_tax:
    plugin: sub_process
    source: field_core_mbr_misconduct_tax
    process:
      target_id: tid
  field_core_executive_tax:
    plugin: sub_process
    source: field_core_executive_tax
    process:
      target_id: tid
  field_core_business_tax:
    plugin: sub_process
    source: field_core_business_tax
    process:
      target_id: tid
  field_core_related_rule_tax:
    plugin: sub_process
    source: field_core_related_rule_tax
    process:
      target_id: tid
  field_core_desktop_image:
    plugin: sub_process
    source: field_core_desktop_image
    process:
      target_id: fid
      alt: alt
      title: title
      width: width
      height: height
  field_core_official_dt:
    plugin: iterator
    source: field_core_official_dt
    process:
      value:
        plugin: substr
        source: value
        start: 0
        length: 10
  field_invstr_alrt_ctgry_tax:
    plugin: sub_process
    source: field_invstr_alrt_ctgry_tax
    process:
      target_id: tid
  field_invstr_alrt_official_dt:
    plugin: iterator
    source: field_invstr_alrt_official_dt
    process:
      value:
        plugin: substr
        source: value
        start: 0
        length: 10
  field_invstr_alrt_keywords_tx:
    plugin: get
    source: field_invstr_alrt_keywords_tx
  field_link_details:
      -
        plugin: skip_on_empty
        method: process
        source: field_link_details
      -
        plugin: migration_lookup
        migration: d7_field_collection_link_details
        no_stub: true
      -
        plugin: iterator
        process:
          target_id: '0'
          target_revision_id: '1'
  field_core_keywords:
    plugin: get
    source: field_core_keywords
  uid:
    plugin: default_value
    default_value: 1
  sticky:
    plugin: default_value
    default_value: 0
  'body/value': content
  'body/format':
    plugin: default_value
    default_value: full_html
migration_dependencies:
  required:
    - field_collection_to_paragraph