Media replace in media_library_widget
Media replace in media_library_widget adds a Select new
button to existing items in Drupal's Media Library field widget. Editors can
replace a media item directly from the Media Library without removing it
first, while preserving its position in the field.
Features
Drupal's Media Library allows editors to select, add and remove media items
from entity reference fields. However, replacing an existing item normally
requires removing it first and then selecting a new one. This module provides
a direct replacement workflow.
- Adds a Select new button to every existing media item in supported Media Library widgets.
- Opens the Media Library in a modal dialog when the button is clicked.
- Replaces the original media item after the editor selects a new item.
- Preserves the original field position and item delta.
- Restricts the replacement selection to the media bundles allowed by the field.
- Uses Drupal AJAX and the Media Library opener API.
- Works with Drupal's standard
media_library_widget. - Also integrates with the
media_library_media_modify_widgetwhen the Media Library Media Modify module is installed. - Respects normal entity access, field access and form validation.
This module is useful when editors frequently update images, documents or
other media attached to content and need to keep the existing field order
unchanged. Typical use cases include replacing a banner image, updating a
document, changing an event image or updating media in a multi-value field.
Post-Installation
After installing and enabling the module, the replacement button is enabled
by default. It is automatically added to fields using supported Media Library
widgets when those fields contain existing media items.
The module does not create new content types, media types, fields or views.
No additional field configuration is required.
The module provides an optional configuration page at:
Administration > Configuration > Media > Media replacement settings (/admin/config/media/media-replace-media-library-widget)
Administrators can use this page to enable or disable the replacement button
globally. The module only displays the button for existing media items;
empty field slots continue to use the normal Media Library workflow.
Additional Requirements
This module requires:
- Drupal 10 or Drupal 11.
- The Drupal core
Media Librarymodule.
No additional PHP libraries, JavaScript libraries or contributed modules are
required for the core functionality.
Recommended modules/libraries
No additional module is required. The module can optionally be used together
with
Media Library Media Modify
when advanced media editing or the
media_library_media_modify_widget is needed.
Similar projects
Drupal core's Media Library provides the standard workflow for adding,
selecting and removing media items from entity reference fields. This module
complements that functionality by adding a direct replacement action for
existing items.
The
Media Library Media Modify
module focuses on editing or modifying media items in context and provides
additional widget options. This project focuses specifically on replacing an
existing media reference while preserving its position in the field.
Supporting this Module
This project is maintained as community-contributed Drupal software. There is
currently no external funding page or sponsorship program for the project.
Community Documentation
Project page:
https://www.drupal.org/project/media_replace_media_library_widget
Community documentation, video walkthroughs and a demonstration site may be
added as they become available.
Additional Information
The replacement functionality was originally developed as part of the
drpl_media module and is now available as a standalone project
for Drupal sites that need a focused Media Library replacement workflow.
The module does not modify media entities directly. It only changes the media
reference stored in the field, using Drupal's standard Media Library,
Entity Reference and AJAX APIs.