Drupal 8 Node Reference In Migrate

December 1st, 2017  | Categories: Drupal, Drupal 8, Drush 8


I have a content type linking to another content type (entity reference). I have a JSON feed that has that information of node titles. It’s using the same examples from the previous two blog posts but slightly modified to add some more data. For example, one item of the JSON array looks like the following:

            "title": "Drupal 8 Change Taxonomy Term In Migrate",
            "pubDate": "2017-11-29 14:23:04",
            "link": "http://www.longlivethemonkey.com/syntaxnotes/?p=300",
            "guid": "http://www.longlivethemonkey.com/syntaxnotes/?p=300",
            "author": "admin",
            "thumbnail": "",
            "description": "content...",
            "content": " here's some cool content... to fill in later... well maybe never cause this is just test crap",
            "categories": [
            "articles": "WINTER COAT,BOXER SHORTS,T SHIRT"

The only thing that’s new is articles. These articles are titles of nodes in the Article content type. Using data like this I need to modify the previous YML to import and link to the articles.

I first need to explode the string then find the reference and import it into the new node.

Here’s what my YML looks like (for just handling the articles… the rest of the YML is the same as the previous blog entries… except in the fields I added sn_articles for the articles):

  # explode the string, find the article entity and populate
      plugin: explode
      source: sn_article
      delimiter: ','
      plugin: entity_lookup
      ignore_case: true
      value_key: title
      entity_type: node
      bundle_key: type
      bundle: article

It successfully links to the proper article!

Also since I didn’t put a cheat sheet before on some drush migrate commands:

$ dr migrate-import migration_try_6

$ dr migrate-rollback migration_try_6

$ dr migrate-import migration_try_11 --update

$ dr mmsg migration_try_12
No comments yet.