- Issue created by @eojthebrave
- Status changed to Needs review
8 months ago 5:20pm 27 March 2024 - πΊπΈUnited States eojthebrave Minneapolis, MN
I was able to get media_insert working again after making a few changes.
I refactored the code in insert_media.module to make use of hook_insert_styles, hook_insert_render, and hook_insert_variables instead of relying on hook_insert_process to do all the the work. Amongst other things this solves an issue where the insert-template elements that the JS code is looking for where not getting added to the page with the correct class.
I modified
Drupal.insert.Inserter.#insert
so that it passes the `event` when called and then if successful calls `event.preventDefault()`. Without this, when used with a media library widget, the 'click' on the Insert button would propagate to the "Remove" button for the media entity card. So after the embed code is inserted it would then remove the entity from the media field, and cause the form to reload.In order to handle the fact that the media library widgets can have multiple values, and each one requires a different insert-template, I added the `$insertElement` as an argument to hook_insert_render(). This allows access to the media entity associated with each Insert button.
Without these changes when you try and use media_insert it:
- Won't insert the embed code because the Handler.js code can't find the template element
- The page is refreshed every time you click the Insert button
- Merge request !8[#3436455] Fix insert_media after upgrades to Insert to make it work with CKEditor. β (Merged) created by eojthebrave
-
Snater β
committed 22a2e511 on 3.x authored by
eojthebrave β
[#3436455] Fix insert_media after upgrades to Insert to make it work...
-
Snater β
committed 22a2e511 on 3.x authored by
eojthebrave β
- Status changed to Fixed
8 months ago 10:55am 2 April 2024 Thanks a lot for the patch. I was able to reproduce the issue. The fix is part of 3.0.0-beta6 β .
Automatically closed - issue fixed for 2 weeks with no activity.