0

I'm performing migration from Drupal 9 into another Drupal 9 project. Let's say "content features" migration.

In a node migration I'm trying to create stubs for media items.

The media source has two id keys: mid, langcode. The mid key is getting from field's target_id property. But there is no language property on field's level and I'm trying to pass node's language as second id value for the media lookup.

The migrate_lookup plugin tries to find media entity by mid and langcode properties: MigrationLookup::transform():

if (isset($this->configuration['source_ids'][$lookup_migration_id])) {
  $lookup_value = array_values($row->getMultiple($this->configuration['source_ids'][$lookup_migration_id]));
}

then getMultiple() tries to get values from the current iteration.

Does someone know how to pass root row instead of iteration row?

...
process:
  langcode: langcode
  ...

  field_cover_image:
    - plugin: sub_process
      source: field_cover_image
      process:
        lang:
          plugin: default_value
          default_value: 'en'
        target_id:
          plugin: migration_lookup
          source: target_id
          migration: migrate_media_image
          source_ids:
            migrate_media_image:
              - target_id
              - ROOT_ROW_SOURCE_PROPERTY_LANGCODE

I wonder also if it possible to use constants within sub_process and $row->getMultiple()?

An example:

...
      process:
        target_id:
          plugin: migration_lookup
          source: target_id
          migration: migrate_media_image
          source_ids:
            migrate_media_image:
              - target_id
              - constants/default_language

1 Answer 1

0

I figured it out from sub_process plugin's documentation:

/**
 * Available configuration keys:
 *   ...
 *   - include_source: (optional) If TRUE, all source plugin configuration and
 *     values will be copied into the sub-processed row in a new property named
 *     for the source_key configuration value (see below). Defaults to FALSE.
 *   - source_key: (optional) If include_source is TRUE, this
 *     is the name of the property of the sub-processed row which will contain
 *     the source configuration and values. Ignored if include_source is
 *     FALSE. Defaults to 'source' if no value is provided.
 */

And used it as:

  field_cover_image:
    - plugin: sub_process
      source: field_cover_image
      include_source: true
      source_key: root
      process:
        target_id:
          plugin: migration_lookup
          source: target_id
          migration: migrate_media_image
          source_ids:
            migrate_media_image:
              - target_id
              - root/langcode # <- get property from the root row

And of cause constants also will be available:

migrate_media_image:
  - target_id
  - root/constants/default_language

An alternative could be creating iteration property as default value:

  plugin: sub_process
  source: field_cover_image
  process:
    lang:
      plugin: default_value
      default_value: 'en'

and refering to it as current iteration destination property @lang:

    lang:
      plugin: default_value
      default_value: 'en'
    target_id:
      plugin: migration_lookup
      source: target_id
      source_ids:
        migrate_media_image:
          - target_id
          - '@lang'

The content/media types set to be translatable but actually there is just one language and I can "hardcode" it, but it is better to use dynamic value.

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.