0

I'm working on a migration from a CSV into a Drupal 8 site, creating School nodes that include an entity reference field for a Sport taxonomy. The new taxonomy terms I want to use all exist within Drupal already, but they're nested such that a sport ("Basketball") is listed as a parent term, with child terms ("Boys" and "Girls") below them. Because the child terms' names are the same under multiple sports, I'm attempting to target the mapped destinations by their term IDs instead.

Here's an example of what I've tried – this looks similar to a previous answer and produces no errors, but also no Sports mappings. Other tweaks I've made have resulted in either the original terms ("Basketball Men") being imported as new terms or the importer producing errors because those terms aren't IDs.

source:
  plugin: csv
  path: sites/default/files/data/schools.csv
  delimiter: ','
  enclosure: '"'
  header_row_count: 1
  keys:
    - id
  column_names:
    -
      id: 'Unique ID'
    -
      sports: Sports
process:
  field_sports:
    -
      plugin: explode # Because schools have multiple terms...
      delimiter: ',' # ...separated by a comma in the spreadsheet
      source: sports
    -
      plugin: static_map
      source: sports
      map:
        'Basketball Men': 37 # Corresponds with the ID for Basketball > Boys
        'Volleyball Men': 74 # Corresponds with the ID for Volleyball > Boys
        'Volleyball Women': 75 # Corresponds with the ID for Volleyball > Girls
        [...]
    -
      plugin: entity_lookup
      value_key: tid
      entity_type: taxonomy_term
      bundle_key: vid
      bundle: sport # The ID of the taxonomy vocabulary

Is there an obvious adjustment I need to make in order for these terms to import properly?

  • Remove the source: sports line from the plugin: static_map section: The static map should use the output from the preceding explode to get the values, not the whole string from the CSV – Hudri Oct 10 at 5:42
  • @Hudri Thanks, that makes sense. However, now it's showing all the items as "ignored" when I rerun the import, and the Sport terms still aren't being imported. Assuming that means it's not finding any differences between the content that's currently imported and what it's trying to import? – Kurt Oct 10 at 5:59
  • Most likely you'll need to integrate sub_process somewhere in the chain, because there are multiple values. – Hudri Oct 10 at 7:15

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.