1

I have a node migration using the d7_node source plugin.

I'm trying to migrate the values of a multi-value taxonomy term reference field into a multi-value taxonomy reference field in D9. There is a separate migration to import the taxonomy terms that works great.

In my node migration, I have something like:

field_my_tax_field:
  plugin: migration_lookup
  migration: my_taxonomy_migration_id
  source: field_my_d7_tax_field

However, this throws an exception and the migration fails. When I throw a breakpoint in Drupal\migrate\Plugin\migrate\process\MigrationLookup::transform() (where the exception is thrown), I can see that the value being passed is an array, but the lookup plugin wants a scalar value. The array passed is something like:

['target_id' => 123]

With this info, I can make this work by updating my migration config with something like:

field_my_tax_field:
  - plugin: callback
    callable: reset
    source: field_my_d7_tax_field
  - plugin: migration_lookup
    migration: my_taxonomy_migration_id
    

Using reset() like this feels loose. And it seems weird that this extra step is necessary, this seems like use-case #1 for the migration_lookup function.

What am I missing? How can I do this in a better way?

1 Answer 1

1

One option is to use the Drupal\migrate\Plugin\migrate\process\SubProcess (sub_process) plugin:

Runs an array of arrays through its own process pipeline.

The sub_process plugin accepts an array of associative arrays and runs each one through its own process pipeline, producing a newly keyed associative array of transformed values.

field_my_tax_field:
  plugin: sub_process
  source: field_my_d7_tax_field
  process:
    target_id: 
      plugin: migration_lookup
      migration: my_taxonomy_migration_id
      source: target_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.