0

For a Drupal 7 to Drupal 8 migration, we're taking what was a Quotation content type and migrating it into an Article content type, joining a ton of nodes that are staying as Articles. To distinguish, I want to add a taxonomy term "Quotation" to the field_categories (which exists on Articles D7 and D8 but not on Quotation).

So i'm "simply" trying to add a value not from a source, but hard-coded. My source plugin is d7_node (namespace Drupal\node\Plugin\migrate\source\d7).

I'm flailing a bit; tried entity_generate but couldn't figure out how to tell it to use a constant and/or default value rather than looking for something from source.

Even this didn't work, when i tried to test the simplest thing i could think of when already knowing the term ID of an existing term:

 field_categories: plugin: iterator source: field_categories process: target_id: - plugin: default_value default_value: 10838 

Can one use the default_value plugin or something like it for the 'source:'?

I'm about to stick my non-source value into what comes from the source with a prepare row hook, but it seems there ought to be an easier way.

Note that in this case there is nothing from field_categories in the source to worry about, but i'm also interested in the case of adding a new, hard-coded-into-the-migration term into a field that will have content, in my case field_tags.

0

2 Answers 2

0

Well, i don't like it, but this works:

<?php use Drupal\migrate\Row; use Drupal\migrate\Plugin\MigrateSourceInterface; use Drupal\migrate\Plugin\MigrationInterface; /** * Implements hook_migrate_MIGRATION_ID_prepare_row() for upgrade_d7_node_quote. */ function portside_upgrade_migrate_upgrade_d7_node_quote_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { $term_name = 'Portside Quotation'; $term_array = \Drupal::database()->select('taxonomy_term_field_data', 't') ->fields('t', ['tid']) ->condition('vid', 'categories') ->condition('name', $term_name) ->execute() ->fetchCol(); if (isset($term_array[0])) { $row->setSourceProperty('field_categories', [['tid' => $term_array[0]]]); } } 

I create the taxonomy term with default content, so it's there after site install and ready for the migration.

In the migration's YAML file (for upgrade_d7_node_quote), there's simply a plain mapping as if field_categories were a real thing:

 field_categories: plugin: iterator source: field_categories process: target_id: tid 

And remember, there is no field_categories in the source. The migration doesn't mind at all and works fine with one inserted into the source in this prepare row hook.

0

I found the following worked for me...on the first migration I ran:

 field_type: - plugin: default_value default_value: 'Hall' - plugin: entity_generate entity_type: taxonomy_term value_key: name bundle: place_type 

The second migration I ran, using exactly the same yaml to create the same content type, didn't work. I got a "Missing bundle for entity type taxonomy_term" error. Adding the bundle key as below fixed it:

 field_type: - plugin: default_value default_value: 'Library' - plugin: entity_generate entity_type: taxonomy_term value_key: name bundle_key: vid bundle: place_type 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.