Migrating image field to media entity reference on node

Created on 5 August 2022, over 2 years ago
Updated 24 May 2023, over 1 year ago

Problem/Motivation

The module page mentions

Image and file fields of the Drupal 7 source instance are migrated as media reference fields in Drupal 8|9.

The README mentions something slightly different:

Transforms image fields to media image fields.

My expectation is that an node image field on a Drupal 7 site with media module installed with an Image media type will become a media entity reference field in Drupal 8|9|10.

My actual result is that the image field remained an image field.The file_entity is correctly migrated to a media entity and files and images and entity references exist on the media entity. The files themselves are all referenced and migrated with the exception that image fields are still image fields e.g. field.storage.node.field_image is type image and target_type file rather than type entityreference and target_type media.

It is hard for me to understand exactly how the module works, and I tried to look at MigratePluginAlterer, but was confused as how any of that would migrate an image field to a media reference field on a node.

Steps to reproduce

Proposed resolution

Questions I would like to answer to figure out my next steps to be able to assert a successful migration:

* Is my expectation correct?
* If Yes, where in the code base can I find out where image fields should be migrated into media reference fields so I can hunt down what is going wrong with media_migration (or other modules combined on the site like commerce_migrate)?
* If No, is it possible to add "image: media_image" in upgrade_d7_field? Is there a module that does this?
* If No, what's the expectation for this module if fields remain in the "old way" and so any new uploads are not tied to media entities and the site cannot leverage the "new way" of Media Library?

Remaining tasks

API changes

N/A

πŸ’¬ Support request
Status

Active

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    The default Article content type has field_image, which is an image file field. You need to delete that before generating the migration config or else it will get confused since the field storage already exists as the wrong type.

  • πŸ‡«πŸ‡·France erwangel

    My request is a bit different but concerns the same issue: is it possible to have field_image migration to media entity as an option ? In other words, is it possible to leave image_field as image (and migrate associated items without changing the field type) and only change file(image) field to media file ?

  • πŸ‡³πŸ‡±Netherlands ndf Amsterdam

    We have a similar (or same issue) on a migration from Drupal 7 to Drupal 9.5 with media_migration 1.x-dev (of today d369908a)

    Problem/Motivation

    • Media entities are successfully created for image fields.
    • On the node level, the image field remains as an image field (type file) instead of being converted to a media reference field (type entity_reference).
    • The image field on the node is empty and does not reference the migrated media entities.

    Expected Behavior

    • The image field should be transformed into a media reference field.
    • The field should reference the corresponding media entities.

    Steps to Reproduce

    1. Migrate nodes with image fields using media_migration.
    2. Check the destination node fields after migration.

    Proposed Resolution

    Update the migration process to properly transform image fields into media reference fields and link them to migrated media entities.

  • πŸ‡³πŸ‡±Netherlands ndf Amsterdam

    Just now I tested the media_migration with a standard drupal 7 installation; and then the image field is migrated to a media field.

    As expected because of the media_migration module description: "Image and file fields of the Drupal 7 source instance are migrated as media reference fields in Drupal 8|9|10."

    So my case above in [3302125#comment-15866766] is a bug that happens is certain cases.

Production build 0.71.5 2024