Drupal is a registered trademark of Dries Buytaert

Updated 2
Since the release 3.0.1 it's possible to convert Image fields to Media using update hooks. To do this, you must first create a Media field. Also, you can omit specifying bundles, just pass an empty array []. An example of hook implementation:

/**
 * Migrate field_image to field_media_image.
 */
function my_module_post_update_1001(&$sandbox) {
  \Drupal::moduleHandler()->loadInclude('image_field_to_media', 'inc', 'image_field_to_media.batch');
  image_field_to_media_populate_media_field('node', ['article', 'page'], 'field_image', 'field_media_image', $sandbox);

  if ($sandbox['#finished'] === 1) {
    \Drupal::messenger()->addStatus(t('Updated entities: @number.', [
      '@number' => $sandbox['results']['processed'],
    ]));
  }
}

Updated 1
Since the release 2.0.1 it's possible to add images to the existing Media field. In this case a new Media field does not created.

Helps convert existing image fields to Media fields. The module adds a new Media field to the bundle and updates all entities. After that, each entity will have the Media field populated with the same image items that the Image field has. To prevent of duplicate creation, sha1 hash of image files compares.

Configuration

For the module to work, the following conditions must be met:

  1. The "Image" media type should exist in your system.
  2. The "Image" media type should have the field of the "Image" field type with the machine name "field_media_image".

So check if they exist, and if not, then create them. You can do it from UI by visiting "/admin/structure/media/add"
Also, you can copy missing config files from "/core/profiles/standard/config/optional" to the related folder of your profile.

Uses

1. Visit "Manage fields" tab and choose the Image field you want to migrate to Media.
2. Click on the "Clone to media" operation.
3. Enter the name of the Media field and click on the "Proceed" button.

Similar projects

Sponsors

 Nextcorp, G&G SARL www.gontcho.com

Activity

Total releases
3
First release
Dec 2024
Latest release
7 months ago
Release cadence
107 days
Stability
67% stable

Release Timeline

Releases

Version Type Release date
3.0.1 Stable Jul 12, 2025
3.0.0 Stable Dec 9, 2024
3.0.x-dev Dev Dec 9, 2024