3

My goal is to take an existing D6 content type ('mini') and migrate it into one of two specific D8 content types based on its current D6 URL Alias (either 'course' or 'page') and where this alias falls in the hierarchy.

I've have successfully written a simple source plugin that adds the alias into RowSource.

How do I control the destination plugin so I can migrate into the appropriate bundle - either 'page' or 'course'? Is there any property of $row that can be adjusted to do so?

Or is this process more involved?

I know that nodes use the 'entity:node' destination plug-in, but how can I extend this per above? It's unclear to me what exact class the destination plug 'entity:node' represents

Any insight would be much appreciated.

Thanks!

2 Answers 2

2

In your config, use a row instead of the default value plugin.

Instead of this:

process:
  type:
    plugin: default_value
    default_value: course
  title: title
  etc.

use this:

process:
  type: target_bundle
  title: title
  etc.

Then you can set the target_bundle dynamically in your source class's prepareRow function.

$row->setSourceProperty('target_bundle', $target_bundle);
2
0

Here is how I could achieve a dynamic destination bundle based on a condition:

id: dynamic_bundle_migration_example
label: 'Dynamic Bundle Migration Example'
description: 'Demonstrates how to define a dynamic bundle based on an arbitrary condition.'
source:
  plugin: d8_entity
  entity_type: paragraph
  bundle: full_text
  key: migration_source_db
process:
  iframe_regex:
    plugin: default_value
    default_value: '/<iframe/'
  iframe_found:
    plugin: callback
    callable: 'preg_match'
    unpack_source: true
    source:
      - '@iframe_regex'
      - 'field_text/0/value'
  type:
    plugin: static_map
    source: '@iframe_found'
    map:
      '1': 'embed'
      '0': 'wysiwyg'
    default_value: 'wysiwyg'
    bypass: true
  field_text:
    plugin: sub_process
    source: field_text
    process:
      value: value
      format:
        plugin: default_value
        default_value: 'rich_text_full'
  destination:
    plugin: 'entity_reference_revisions:paragraph'

Roughly speaking, you don't need to set the default_bundle property on your destination configuration if you provide the bundle information inside your process configuration.

The above migration migrates paragraph entities of either bundle embed or wysiwyg.

It does this by setting the type destination property to a dynamic value. It's simply checking for whether field_text has an iframe on it's value. If so, type is embed, otherwise wysiwyg.

--

PS: You need to check what is the bundle key for the entity type being migrated. Not all entity types' bundles are called type.

Taxonomy Term entities, for example, have its bundle key called vid.

Here is a one-liner for checking your destination entity type's bundle key using Drush:

drush ev "print \Drupal::entityTypeManager()->getDefinition('taxonomy_term')->getKey('bundle');"

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.