Drupal Field Content Migration with Views Bulk Edit module
4 min readJun 8, 2023
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)”.
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 thefield_status
list field to the newly setup taxonomy term listfield_status_taxonomy
.
Step 2 — Setup a new View with the Views Bulk Edit module
- Go to https://drupal.local/admin/structure/views.
- Set View name to “Migrate Achievement Standard Status Field”.
Note: You can leave View Settings as is for now, we’ll update those later.
- Select option to “Create a page” in Page settings.
- Save and edit.
Step 3 — Update View configs
- Set Format option to use HTML List.
- Set Show to Fields
- Add a “Views bulk operations” field (global) … And Select “Modify field values”
- 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.
- 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:
- 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
- Change Access to Admin Role
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.