Drupal Field Content Migration with Views Bulk Edit module

Drupal migration

Use the Views Bulk Edit module to migrate content for individual fields on selected content types. This is made possible with use of Drupal’s Views Bulk Edit module, which allows us to setup new Views for the purpose of migrating fields.

Prerequisites

  • Label source fields “(Old)”
    Before starting, mark legacy source field labels with an indicator so it’s more obvious which fields are old. E.g. Navigate to source field settings and change label from “Some Field” to “Some Field (Old)”.
Marking old field labels with “(Old)” makes it easier to identify in Drupal CMS.
Marking old field labels with “(Old)” makes it easier to identify in Drupal CMS.

Step 1 — Setup new destination fields

  • Create destination fields
    Create new destination fields to which source field values will be migrated to. In this example, we will be migrating the content of the field_status list field to the newly setup taxonomy term list field_status_taxonomy.
Source and destination fields in Drupal CMS.
Source and destination fields in Drupal CMS.

Step 2 — Setup a new View with the Views Bulk Edit module

View basic information
View basic information
  • Select option to “Create a page” in Page settings.
Create a page
Create a page


Save and edit.

Step 3 — Update View configs

  • Set Format option to use HTML List.
Format options
Format options
  • Set Show to Fields
Show fields
Show fields

Add a “Views bulk operations” field (global) … And Select “Modify field values”

Bulk operations
Bulk operations
Bulk operations
Bulk operations
  • Now add both the source field (`field_status`) and the destination field (`field_status_taxonomy`), and remember to add a label too which will display in the list.
Taxonomy
Taxonomy
  • Add Content Type in Fields options, so that this is exposed in the list.
  • Re-arrange fields into logical order: Title, Content Type, Source Field, Destination Field, etc.
  • This is what Fields should look like:
Fields
Fields
  • Configure Filter criteria
  • Remove “Content: Published (=Yes)” rule, as we want the migration to apply to all nodes.
  • Add Content Type, then filter to relevant content types, so only those are impacted.
  • Add old field (In this case “Status (Old)” as a filter — We will expose this too.
  • Set Pager to Display All Items
Page settings
Page settings
  • Change Access to Admin Role
Access restrictions
Access restrictions

Step 4 — Running the Field Migration

Load View by path (https://drupal.local/migrate-achievement-standard-status)

Then apply

  • Select destination field to change.
  • Then map the source / destination values.
  • Repeat for each option.

Step 5 — Delete Legacy Source Fields

Now that content has been migrated, it’s time to delete the source fields.

  • Ensure all fields to be removed are marked not required in field settings.
  • Go to each field and delete the field in the CMS.

Search through code and unwire any references to the old fields.
Caution: make sure you search the following:

  • Twig template code.
  • YAML configs.
  • Custom module and theme preprocess code.

References