Ajax callback runs for each form in case "media_library_edit=ajax" in URL

Created on 25 August 2022, over 2 years ago
Updated 3 May 2023, almost 2 years ago

Problem/Motivation

In hook "media_library_edit_form_alter" we have condition if "media_library_edit=ajax" present in URL the code will add callback "_media_library_edit_media_edit_save" for ajax for each form.
And in case of multiple media fields tree (like a media field has another media field) the "media_library_edit=ajax" parameter will go with next ajax request.
So, accordingly to the "media_library_edit_form_alter" hook behavior the next media library form will have wrong ajax callback

Steps to reproduce

Create a media field with another media field and allow to edit the first level media.
Try add/remove the media file in the second level media field through the first level media.

Proposed resolution

Add a new condition to "media_library_edit_form_alter" hook

Remaining tasks

-

User interface changes

-

API changes

-

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine slivorezka

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France Fabsgugu

    Hello,
    The patch is not working properly.
    When I want to select a media at the second level, it closes the popin of the first level media, without saving the change.

  • πŸ‡©πŸ‡ͺGermany marcoliver Neuss, NRW, Germany

    We also encountered this issue recently. We have some instances of nested media (e.g. an Image media referenced inside of a Contact media, referenced on a page node), all showing the edit button in the Media Widget.

    Once I'm down the the second level of media inside the modal (showing the Media Library to select a new Image), the AJAX request suddenly no longer receives JSON as a response, but HTML, causing an AjaxError.

    Sadly, as @fabsgugu stated, the patch at #5 πŸ› Ajax callback runs for each form in case "media_library_edit=ajax" in URL Needs work just closes the modal without anything being saved.

    Maybe someone with more mileage on this project can chime in here, but it seems to me that once we're down to the Media Library level, the response for that widget will always contain a CloseDialogCommand and thus close the modal on us?

Production build 0.71.5 2024