0

In Drupal 8 How to import parent/child taxonomy term from csv file with migrate.

This is my csv file:

id,title,body,country,province
1,first,some body,Italy,Rome
2,second,some body,Germany,Berlin

I created a taxonomy vocabulary named 'location' then I created a node field named 'field_location' with the selected checkbox 'Create referenced entities if they don't already exist'

I want to import into the node field 'field_location' the term 'country' as parent and 'province' as child of 'country'

here if my code:

id: my_group_data
migration_group: mygroup
label: 'my group Data from CSV'
source:
  plugin: csv
  path: sites/default/files/node-import.csv
  header_row_count: 1
  keys:
    - id
  column_names:
    0:
      id: 'Unique Id'
    1:
      title: 'The title'
    2:
      body: Body
    3:
      country: Country
    4:
      province: Province

process:
  title: title
  body: body
  field_location:
    plugin: entity_generate
    source: country
    entity_type: taxonomy_term
    bundle_key: vid
    bundle: country
    value_key: name
  field_location:
    plugin: entity_generate
    source: province
    entity_type: taxonomy_term
    bundle_key: vid
    bundle: focus
    value_key: name
destination:
  plugin: 'entity:node'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.