Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

Image field to media

741 sites Security covered
View on drupal.org

This module helps migrate existing Drupal Image fields to Media fields. It can either directly convert an Image field to a Media field, populating it with existing images, or create a new Media field and copy the image content. The process ensures that duplicate media items are not created.

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
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Slowing

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