Migrate hierarchical content

Lets say you have an Article content type, with fields to reference the parent and order. If an article has 3 children, each will have a parent reference to the article, and the order field on the children will determine their order.

Here is a migration that can lookup the parent within it's own migration to import the hierarchy correctly.

langcode: en
status: true
id: hierarchy_test
label: Hierarchy Test
source:
  plugin: embedded_data
  data_rows:
    -
      id: 1
      title: Chapter 1
      order: 0
    -
      id: 2
      title: Chapter 1 Section 1
      parent: 1
      order: 0
    -
      id: 3
      title: Chapter 1 Section 2
      parent: 1
      order: 1
    -
      id: 4
      title: Chapter 2
      order: 1
    -
      id: 5
      title: Chapter 2 Section 1
      parent: 4
      order: 0
    -
      id: 6
      title: Chapter 2 Section 1 Part 1
      parent: 5
      order: 0
  ids:
    id:
      type: integer
  constants:
    type: article
    uid: 1
process:
  type: constants/type
  uid: constants/uid
  title: title
  field_parent:
    -
      plugin: skip_on_empty
      source: parent
      method: process
    -
      plugin: migration_lookup
      migration: hierarchy_test
  field_order: order
destination:
  plugin: 'entity:node'

 

Tags
Migration