Development

Drupal Migrate API skip_on_multiple Process Plugin

Here’s a Migrate API process plugin I wrote in Drupal 9 that skips a property or row when more than one value exists. My use case:

  1. My source data has locations; each location has multiple associated organizations
  2. My new Drupal site has locations; each location has a parent organization
  3. I want to only populate the field_parent_org field (an entity reference) if there is a single organization value in the source data for the location
  4. I’m using a custom module called “pdms_migrate”

I’ve stripped out all of the noise from the examples below… hopefully it’s enough to help you understand the example:


modules/custom/pdms_migrate/data/sitecore_locations.xml

In this example, only “My Second Location” will reference a parent organization in Drupal.


modules/custom/pdms_migrate/config/install/migrate_plus.migration.organization.yml


modules/custom/pdms_migrate/config/install/migrate_plus.migration.location.yml

 


modules/custom/pdms_migrate/src/Plugin/migrate/process/SkipOnMultiple.php

 

 

Leave a Reply

Your email address will not be published.