Using the new Drupal 8 Migration API / Module

We at Liip AG believe, that the migration API is the best and most efficient way to import data into Drupal. Here are some reasons, why you should use migrate instead of the feeds module or any other custom importer modules:

  • Since Drupal 8, Migrate API is part of Drupal core
  • Migrate will be maintained and supported as long as Drupal 8 exists as it provides the upgrade path for older Drupal versions to Drupal 8
  • Migrate is sponsored by Acquia and mainly supported by Mike Ryan, a well-known and skilled Drupal developer.
  • Migrate has out of the box support for all important Drupal objects such as nodes, users, taxonomy terms, users, files, entities and comments.
  • Migrate has a Drush integration, that allows you, to run import tasks from command-line or via cron job
  • Migrate maintains a mapping-table, has rollback functionality and even supporting a highwater field, that allows to import only new or changed datasets.
  • Migrate is well documented and there is an example module.

Getting started with Drupal 8 Migrate Module

The Migrate 8 module in core is only an API. There is no user interface. This makes it difficult for new developer to start with Migrate 8.

I suggest you, to install the below listed extension modules right away before you start developing if you want to realize the full potential of migrate:

Migrate Plus (

  • Extends the migration framework with groups
  • Delivers a well documented example module

Migrate Tools (

  • Provides Drush commands for running and managing migrations in Drupal 8

Migration Source Plugins

Installing a fully working Drupal 8 Migrate setup using composer

Instead of starting now to download in install all the module mentioned above, you can use my installation profile based on a composer.json file. Because a lot of modules with specific version are involved, I have prepared a fully working migrate example environment for a Liip hackday.

If you want to quickly start with the migrate module, head over to my github repository and install Drupal 8 Migrate using composer and drush. You just need to follow the instruction in the

Comparing Drupal Migrate 7 with Drupal Migrate 8

Some of you might already have used Migrate 7. A traditional mapping was done in the constructor of a Migration class:

In Migrate 8 this format has been replaced with yaml files. The same mapping as above looks like that in Drupal 8:

Understanding the new mapping with yaml files in Migrate 8

The mapping is quite straightforward.

  • First you have to define your Migrate source. In the example we have used a CSV source plugin. (
  • Then you can map the source fields to a Migrate destination. In our case, we use a node destination (
  • You can map now all source fields to destination fields, for example you map a column of the CSV file to the node title field
  • Every field can be processed and modified before it is passed to the final node field. There are a lot of useful process plugins like “default_value”, “callback” or “skip_if_empty”
  • You can find a list of all process plugins here:
  • Of course you can easily write your own plugins and use them while migrating data

Example: Importing a menu tree and create dummy nodes using Drupal Migrate 8

For demonstration purpose I created a small module, that reads a menu tree from a CSV file and imports into Drupal.

The module is split into 2 tasks:

  1. Creating a page node for every row in the csv file
  2. Create a menu item for every row and attach it to the correct node

Migrate handles these dependencies in the yaml file:


See the full module code here:

Developing your own Drupal 8 migrate modules and fighting caching issues

You have learned, that the whole migration mapping is now done in yaml files. But how about writing your own migration yaml files?

Unfortunately, there are some pitfalls for new Drupal 8 developers. Because of the Configuration Management Interface ( of Drupal 8, all yml files in the “config/install” directory are only imported when installing the module.

This is very impractical if you want to develop new configuration files. To address this, a module “Configuration Development” ( which resolves the caching issues can be installed. It is possible to import certain yml files on every request. But unfortunately drush commands are not supported yet. So we need to add all yaml files we want to import into a new section in our

Then we can run the following commands after updating the yml file. This will import the new configuration file into CMI.

In short:

You always have to remember, that you have to import the yaml files and clear the cache after changing the mapping before executing the migration again.

Testing and running your migration

If your module is set up correctly, you can run “drush ms” to see if the migration is ready:


Now you can run the migration using


If you want to update already imported items you can use the –update option:


Advanced example importing a JSON source into Drupal nodes

During the last hackday at Liip I wrote a small module that is consuming a JSON source from importing some postings and comments to a Drupal 8 website.

The module is split into 3 tasks:

  1. A feature module that installs the node type and fields called “migrate_posts”
  2. A migration importing post nodes
  3. A migration importing comments and attaching them to the already imported nodes

You can find the feature module here:

The migration module itself is here:

Migration Process Plugin

Inside the migration module from above you will find a simple process plugin. The subject field of a comment in drupal only accepts a certain number of chars by default. Therefore I wrote a small process plugin, that truncates the incoming subject string:

The process plugin needs an annotation ( to be picked up by the migration API. You can later refer to the id in the yaml file:

You can see the whole module code under:

Final Words

At the moment, there migration is under heavy development. For Drupal 8.1 a lot of changes have been made and these changes were breaking a lot of helper modules. Especially the Migrate UI is not working since several months now under Drupal 8.1. You can see more information under

But nevertheless, Migrate 8 is getting more and more mature and stable. And it’s time to learn the new yaml syntax now! If you have any suggestions, just drop a comment.

I think you mean ‘drush cde ‘ rather than ‘drush cdi ‘ in the section on caching issues.

    drush cde is shorthand for configuration export so cdi is the correct command. however, I only got this working after switching to the dev branch of config_devel.

    still wrestling with migrations though, more specific the entity_lookup plugin…


Just as a heads up, cdi alias has changed to cdi1, aka config-devel-import-one, as the developer has appear to updated the module.

Could this technique be used to import translated content in bulk?

Yes ist possible to import multilingual content with Migrate 8. I recently did that.

You need at least Drupal 8.2-dev and you will have to create a migration for every language.

In the end you will have only one node but every language lives in a separate migration. The main language is the source migration.

    Hi Jon ,
    Any example of how you did that ? I’m triyng to import from a DB where transaltion are in the same row ( name_en , name_fr , … bad design ) But can’t figure how to do that.
    Thanks !

not able to migrate to drupal 8, module errors I found this amazing blog. It is related to this article. You must read. Although thank you for sharing your thoughts, this has added to my knowledge.

Is it possible to use the Migrate API to update existing entities?

For example, I successfully imported some Product entities. In the future I might want to update specific fields using a CSV file, for example the prices.

I am now not positive the place you are getting your info, however great topic.
I needs to spend a while learning much more or figuring out more.
Thank you for magnificent information I used to be in search of this
info for my mission.

Leave a Reply