4

I need to migrate a CSV file of 3000 Taxonomy terms with depth of 5 levels deep. This is a small sample of the CSV comma-separated values file.

About Us
About Us, Our Programs
About Us, Our History, Timeline
Mission
Mission, Community

I want these values to be inserted into a Vocabulary, It should have the depth and it should ignore parent terms it has already created. It should look just like this in Drupal

About Us
-Our Programs
-Our History
--Timeline
Mission
-Community

I created a simple migrate yml file that can do this but I had to restructure the CSV file a lot and it is too much manual work. Can regex or something search for the comma delimiter and make the term after a comma a child of the term in front of it? And can it skip or ignore parent terms it already created? Here is my migration and csv file.

id: vocab
label: Migrate terms from the source CSV to taxonomy terms
migration_group: migrated_terms
source:
   plugin: csv
   path: 'public://csv/vocab.csv'
   header_row_count: 1
   keys:
      - uuid
   column_names:
     0:
       uuid: UUID
     1:
       vid: VID
     2:
       name: NAME
     3:
       parent: PARENT
destination:
   plugin: entity:taxonomy_term
process:
   vid: vid
   name: name
   parent:
      plugin: migration
      migration: vocab
      source: parent

csv file

"uuid","vid","name","parent"
"100","myvocab","About Us"  
"101","myvocab","Our Programs","100"
"102","myvocab","Our History","100"
"103","myvocab","Mission"
"104","myvocab","Community","103"

1 Answer 1

0

Have a look at the example in web/core/modules/taxonomy/migrations/d7_taxonomy_term.yml

It sets a term parent_id by looking it up in the same migration:

  parent_id:
    -
      plugin: skip_on_empty
      method: process
      source: parent
    -
      plugin: migration_lookup
      migration: d7_taxonomy_term
  parent:
    plugin: default_value
    default_value: 0
    source: '@parent_id'

For your case you only need to change the migration name:

    plugin: migration_lookup
    migration: vocab

You can use the Migrate Devel module to inspect the migrations while working on them.

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.