Drupal 8 Change Taxonomy Term In Migrate

November 29th, 2017  | Categories: Drupal, Drupal 8

I’ve been tasked with getting data from a SharePoint site into Drupal 8. The SharePoint site will supply a JSON feed and the Drupal 8 site will run a cron to get or update the data. Some of the data needs to be modified before it comes over though; specifically taxonomy.

Using the JSON I used in JSON Migrate Drupal 8 With Taxonomy post, I need to figure out a way to modify the YML to change the taxonomy terms before they go into Drupal 8.

At least this process didn’t take as long as just getting the JSON file into Drupal 8.

I tried to do a custom module first and tried to call a function from it in the migrate script (YML). That didn’t work.

After many times of playing around with it, I got it to work using the static_map plugin. Here’s a snippet of the new YML (same as the one mentioned in the JSON Migrate Drupal 8 With Taxonomy post; just the field_test_categories_0 has been changed:

  # put it into the categories
      plugin: static_map
      source: sn_categories
      value_key: name
      bypass: true
        'CSS': 'CHANGED CSS'
      plugin: entity_generate
      entity_type: taxonomy_term
      bundle_key: vid
      bundle: categories_0

Where you see map you list the terms. On the left is the original term (from the feed) and on the left is what you want it to become (the future taxonomy in Drupal 8).