Score:1

Use deriver in Drupal Migration yml

in flag

I am trying to use the deriver key in a migration yml to have dynamically build migrations for each bundle of an Entity Type (Drupal 9).

I read this and I am trying to use the deriver key to point to a Deriver class in my migration. However it seems that the deriver key is just ignored.

Is there something else that I need to do beside using the deriver key and create a deriver class that inherits from Drupal\Component\Plugin\Derivative\DeriverBase?

This is the migration yml:

id: person_roles
label: Import 
deriver: Drupal\my_module\PersonRoleImportDeriver
migration_group: my_group
source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  urls: public://this.xml
  fields:
    -
      name: position_name
      label: person role name
      selector: funktion
  ids:
    position_name:
      type: string
destination:
  plugin: 'entity:my_entity'
process:
  name:
    -
      plugin: skip_on_empty
      method: row
      source: position_name
      message: 'Empty source person role'
    -
      plugin: make_unique_entity_field
      entity_type: my_entity
      migrated: true
      field: name
Score:1
ph flag

It's a plugin, so you need to respect the plugin directory structure and namespace.

Your class should be in my_module/src/Plugin/migrate and have the namespace Drupal\my_module\Plugin\migrate.

Stefan Korn avatar
in flag
Hm, I think a Deriver is not a plugin? It has no annotation though. Anyway, if I put the Deriver in the plugin folder it still seems not get called.
Lambic avatar
ph flag
So your deriver class implements getDerivativeDefinitions() and that method never gets called?
Stefan Korn avatar
in flag
Yes, that seems to be the problem.
Lambic avatar
ph flag
Not sure why that would be, I use the same pattern. Does your class include the MigrationDeriverTrait?
Stefan Korn avatar
in flag
it seems its about where the config yml for the migration lives. If it lives in config/install folder the deriver will not get caught, but if it lives in the migrations folder it will work. The Deriver class itself could live anywhere in the namespace. I am just currently understanding the difference between config/install and migrations in that case.
Lambic avatar
ph flag
Ah interesting, we switched to using the migrations directory fairly early on.
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.