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:

The site I’m working on that lead to this code utilizes several profiles, hence the getPersonProfileFields() method (there are other methods for other profile types).

Next, use the mysite_user source plugin instead of d7_user.

Finally, you can map the values to the Drupal 8 image field:


Leave a Reply

Your email address will not be published.