Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Image field to media

751 sites Security covered Drupal 10–11
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

Depends on

Dependencies of the latest stable release

  • media Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Dec 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Slowing

Release Timeline

Releases

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