-
Migrating Specific Fields in a D8 Migration
I recently needed a way to update the value of a single field of a D7 to D8 node migration.
The client was already updating the migrated content so I had to be careful with what I migrated.
The entity destination plugin has a wonderful configuration option that allows you to specify which fields you want to migrate. Search the code here for overwrite_properties.
Here’s how I used this to ignore every field except two:
12345destination:plugin: entity:nodeoverwrite_properties:- field_tax_groups- field_tagsI tested this by editing a node’s title, subtitle, field_tax_groups, and field_tags values. I ran the migration and the edits were preserved on the title and subtitle fields as expected.
-
Migrating a Drupal 7 User Profile2 Image Field to a Drupal 8 User Image Field
Consider this scenario:
- Drupal 7 site contains Profile2 profile called person with image field called field_oldsite_person_image.
- Users each have a profile2 profile associated with their account.
- Drupal 8 site has an image field called field_newsite_user_photo on the user entity itself.
If you need to migrate the image field from the Drupal 7 profile to the Drupal 8 user entity you can extend the d7_user plugin and query for the additional field data. I’m executing an extra query for each user (because the code is in the prepareRow() method), rather than attempting to pull all of the profile data as part of the query in the query() method of the class.
First, create a file in your module like /modules/custom/mysite_migrate/src/Plugin/migrate/source/MysiteUser.php that extends the d7_user plugin:
- Drupal 7 site contains Profile2 profile called person with image field called field_oldsite_person_image.
-
Using GROUP_CONCAT to Combine Rows in a Drupal Query
Recently I was working on a D7 to D8 migration. I was trying to import news items and their taxonomy terms (among many other things). To make things simple I wanted the query results to have (for each node) a single field that contained a comma-separated list of taxonomy terms which I could then explode during the row processing. Using GROUP_CONCAT we can achieve this! Let’s break it down:
The Drupal 7 site has the following structure (focusing on the important bits for this blog post):
123-- News Item (news_item) <content type>---- Categories (field_categories) <field collection>------ Audience (field_term_audience) <taxonomy reference; unlimited values>The migration relies on the d7_node migrate source plugin, which basically queries for nodes of a specific type. The query object looks like this (simplified for this blog post):