Drupal 8 migration - static map with dot

23. 8. 2017

Stable version of Drupal 8 has been here for a while. As successor of Drupal 7 brings huge changes and new features (in good way) that are available in basic installation of Drupal 8. One of those features is migration. Big task in Drupal 8 was to allow relatively easily migrate older versions (Drupal 6 and Drupal 7) to Drupal 8. Migrate API defines set of processes to allow transform and customize all data structures from older Drupals to Drupal 8. Drupal is capable to create a lot of transformations by itself (with some extra modules) but sometimes it is needed to customize certain parts of migrations.

Migration - process

Migration is defined by using yaml files. These files defines "transformations" ("processes" in Drupal migration context) needed for migration itself. All details are available in documentation on drupal.org (https://www.drupal.org/docs/8/api/migrate-api).

Migration process (what should change and how etc.) is defined by plugins. Drupal core defines lot of plugins that are often sufficient for complete Drupal migration. In real world there are cases when available plugin doesn't cover all use-cases so custom plugin is needed.

Static map

One of the core migration plugins is static map plugin. This plugin allows to define relations between features (what should be mapped on what). For example if an old Drupal has value A that should be represented in a new system as B (A -> B) this is job for static map. You can define as many static mapping as you need. Complete documentation with examples is available here https://www.drupal.org/docs/8/api/migrate-api/migrate-process/process-plugin-static-map.

Static map for values with dot

If you read static map plugin documentation you will find at the end that static map currently doesn't support mapping for strings that contain dot (see screen from documentation).

Drupal 8 Migrate static map dot

This issues is already submitted on drupal.org (https://www.drupal.org/node/2827897). Until the issue is resolved it's recommended to create custom plugin for this kind of mapping.

Custom plugin for static map with dot

Possible solutions for this problem is to create placeholder for dot and custom plugin that will convert placeholder to dot. Example of this plugin could look like this:

As you can see from source code it's basically static map plugin with little extension for conversion of placeholder to dot. Example usage if this plugin in yaml files:

Complete module with this custom static map plugin se available here https://github.com/FreelyAgency/drupal8-migrate-process-static-map-dots

Moving from old Drupal to the new one is important decision. Drupal 8 tries hard to simplify whole process so you can enjoy new Drupal 8 features.