Score:1

How can I migrate the values from a multi-value D7 taxonomy term reference field into a D9 field?

in flag

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?

Score:1
in flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.