Generate term with name and taxonomy reference field in one migration

48 views Asked by At

I have (fictional equivalent) situation: I have an xlsx that is going to be migrated by migrate_spreadsheet. The file generates nodes, each nodes consist of 2 reference taxonomy fields ("provider" and "provider_name").

The provider_name is simple, simply if the term that corresponds with the source exists reference it, otherwise generate it first:

field_provider_name:
  plugin: entity_generate
  source: 'provider_name'

However the provider refers to the default name-field, but also a second (inside the provider-taxonomy-term) taxonomy reference field: field_provider_number.

Thus:

field_provider:
  name
  field_provider_number:
     provider_number_taxonomy

How can I using one migration.yml, generate the nodes? The reason is that I need to programmatically call the migrations until now I have 2, but I need to call them using batchImport.

The excel file contains

  • regnr (unique)
  • provider
  • provider_name
  • provider_number

Until know I have 2 migrations. But I need one to use batchImport.

1

There are 1 answers

0
MilanG On

First, I must say that generating more than one type of entities but also more than one destination item during single migration is bad practice. When you roll-back content created "on fly" will remain. Also what if you run with update flag? That's why I strongly suggest making separate migration for each entity type you migrate.

But if you insist, you can create you custom process plugin and do what ever you want from it, create items on fly. You can pass parameters to it as doing for regular plugins. Basically you would have to extend ProcessPluginBase class and provide your transform() method which would find/create taxonomy term on fly and what ever else is needed. Check on some existing plugin - it's fairly straight forward.