Problem/Motivation
When using other modules, such as media entity file replace, which add their own custom submit handler, this module prevents those from working. It does this by completely clearing out the value of $form['actions']['submit']['#submit'] and then applying an ajax submit handler instead.
Steps to reproduce
- Install the media entity file replace module and add it to the form for at least one media type
- Enable this module for any given media entity reference field
- Edit an existing media entity using this module that is also using media entity file replace, and try uploading a replacement file
- Save the media entity, then go to Content -> Files. You will see the file uploaded to replace the existing one, but still marked as temporary and used in 0 places
- Go back to editing the media entity for which you tried to replace the file, and check the file that is attached - open that file to view it, refresh a few times to make sure you are not viewing a cached image. It will be the same image as before, and not replaced as expected
Proposed resolution
See this core issue. It is aimed to resolve the same problem, and it may end up coming to Drupal core once they have worked through the various concerns identified with it.
The patch provided on that issue works, so if this module is not working for you then use that patch instead.
This module could be updated based on that latest patch in order to allow other submit handlers, such as the one in media entity file replace, to work properly.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | 3246687-media-edit-modal-20250306.patch | 1.64 KB | hargurpreet |
Issue fork media_library_edit-3246687
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ahebrank commentedIs this a duplicate of https://www.drupal.org/project/media_library_edit/issues/3231869 ?
Comment #3
teknocat commentedIt seems to be a bit different. The version I am filing this issue against already has the fix from that other issue - it's no longer completely unsetting the #submit array. However, when this module runs its hook after any other modules that may have set other submit handlers, it strips out those handlers that still need to run because it sets the submit handlers to an empty array, without accounting for any that may be set already that need to run. I found this happens when using it in conjunction with Media Entity File Replace, for example. It strips out the submit handler set by that module.
The core patch I linked in the issue description above provides an edit button without causing any issues with submit handlers.
Comment #4
ahebrank commentedUnfortunately I think this is a wont-fix given that we're getting into a pretty complex interaction between contrib modules that are both working against core to some degree. The 1.x version of this module is much simpler and doesn't have many of these alter-related problems, or there's the core patch. Both of these are discussed on https://www.drupal.org/project/media_library_edit
I'm going to leave open for visibility but mark postponed.
Comment #6
prudloff commentedWe encountered a similar problem using media_library_edit with media_name.
media_name adds a custom
#submitcallback (after themedia_library_edit_form_alter()the array, so it is kept).But since the
::submitFormcallback has been removed, the entity is not filled correctly with the new values when reaching the_media_name_form_submitcallback (and it comes before_media_library_edit_media_edit_save()calls::submitForm).What is the reason to remove the
#submitcallbacks?I tried to keep them (see MR) and everything seems to work correctly. (The
#submitcallbacks are executed correctly in order and then the#ajaxcallback closes the modal.)Comment #8
ahebrank commentedComment #9
prudloff commentedComment #10
teknocat commentedYes I agree there is no reason for this module to wipe out all the submit handlers just to be able to do it's thing. @prudloff's solution looks great. I don't think I would have thought of that.
Comment #11
ahebrank commented@prudloff can you change the name of _media_library_edit_media_edit_save() since it no longer saves?
Looking for an RTBC and then can merge.
Comment #12
ahebrank commentedComment #13
dhruv.mittal commentedComment #14
dhruv.mittal commentedComment #15
divyansh.gupta commentedSince there is a unresolved thread moving it to Needs Work, Please resolve the thread.
Comment #16
dhruv.mittal commentedPlease review
Comment #17
divyansh.gupta commentedI have reviewed and tested the latest patch in !11.
✅ The #submit callback is no longer being unset, allowing other submit handlers (such as from Media Entity File Replace) to function correctly.
✅ The function name update issue has been resolved, and $form['actions']['submit']['#ajax']['callback'] now correctly references the updated function.
✅ The form submission process works as expected, and the modal closes properly after submission.
Everything looks good, and I don't see any regressions or issues. Moving this to RTBC.
Comment #18
hargurpreet commentedI also encountered an issue while replacing a file in the modal, but this patch resolved it.
Comment #20
ahebrank commentedComment #21
ahebrank commentedThat MR was targeted at 8.x-2.x so that's where it landed. So we'll need another one for 3.x, if it's intended to apply there.
Comment #22
hargurpreet commentedRestored the issue detail
Comment #26
marcoliverHey everybody, I ported the changes from 8.x-2.x to the 3.0.x branch and opened a new MR.
Comment #27
mlncn commentedmarcoliver's merge requent !26 works beautifully for 3.0.x; good time to get it in now before further development on that branch!
Comment #29
mlncn commented(Oh and respectfully upgraded to major because the way it manifests with Media Entity File Replace #3377463: Incompatibility with media_library_edit results in the file not being replaced and it is extremely difficult to figure out exactly what is happening… if you even notice that people are being served the old file because the new one was never even uploaded (silently failing, no error or warning, seeming successful)!
Comment #30
ahebrank commentedComment #31
mlncn commentedThat has to be a record in speed of commit. Thank you so much! (And everybody who worked on this fix!)
Comment #33
usmanjutt84The PR is merged but
composer require 'drupal/media_library_edit:^3'doesn't bring the changes. Looks like module requires a new release.