Problem/Motivation
With the Core text editor plugin "Embed media", after you insert media into CKEditor5 there is no way to later edit it. So, if for example, you need to change the name of media item, replace image, or adjust the cropping (if you use a contributed cropping module like Focal Point) then you must leave the page, and try to find your item in the Media Library.
Steps to reproduce
1. Enable Media Library module, and in CKEditor5 add the Media Library button.
2. In node edit form upload and insert some document file (eg "Exomple one.pdf") in CKEditor via "Add Media from Library" button.
3. See, that file name is bad, then try to find way for edit this media to change name of this media - In "Edit media" modal window you will see only align and other widget settings, but not fields of current media.
Proposed resolution
Allow Media items to be edited from modal dialog in CKEditor.
Remaining tasks
Start over. The previous work here was for CKEditor4 which has since been retired.
Possibly incorporate code from https://www.drupal.org/project/edit_media_modal
User interface changes
CKEditor5 contextual actions bar will include a new button to edit the media item.
Clicking it will open a modal, just like elsewhere in Core.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #40 | Screen Shot 2022-08-23 at 5.50.50 PM.png | 42.59 KB | dealancer |
| #32 | 3168868-32.patch | 10.6 KB | blade_ukraine |
| #30 | interdiff_29-30.txt | 1.6 KB | ranjith_kumar_k_u |
| #30 | 3168868-30.patch | 4.79 KB | ranjith_kumar_k_u |
| #29 | interdiff_26-29.txt | 3.08 KB | ranjith_kumar_k_u |
Comments
Comment #2
murzHere is my quick patch, that adds secondary "Edit this media" button in modal dialog of CKEditor Media Library widget, that links to media edit form in separate window. If the idea is good, I will try to extend this patch for better UX.
Comment #3
phenaproximaComment #5
chris matthews commentedComment #6
chris matthews commentedIt looks like the Media Library Edit module provides a similar solution. I do think this functionality should be included in Core's media system.
Comment #7
danny englanderI tested this patch and it works great, thanks @Murz. I think it would be ideal to have the media edit open in the same modal if possible for a better UX. @Chris Matthews, I've been using Media Library Edit but there is no provision for editing media entities within CKeditor. But at least for now, this patch gets me part way there.
Comment #8
abhijith s commentedApplied patch #2 on 9.2.x and it works fine.Adding screenshots below.
Before patch:

After patch(The edit media button appears):

But there is some CS issues with this patch.Needed to fix that.
Comment #9
abhijith s commentedFixed the CS issue.
Comment #10
sulfikar_s commentedHi, I applied the #9 patch and it applied cleanly. The patch does the requirements and it fixes the custom commands issue which is in the previous patch.
As per @Danny Englander, I also think it would be ideal to have the media edit open in the same modal if possible for a better UX.
Comment #11
4kant commentedThanks for #9. Works great!
Comment #12
mikkmiggur commented#9 patch works.
I added an access check, the link will be displayed only when the user has access to edit this media entity.
Comment #13
kishor_kolekar commentedpatch #12 Apply Failed.
Added new patch please review.
Comment #14
gauravvvv commentedAfter applying patch #13, Edit this media field is not showing.
Adding screenshot for ref.
Comment #15
chetanbharambe commentedVerified and tested patch #13.
Patch applied successfully and the following issue is appearing
Testing Steps:
# Goto: /admin/Content
# Click on the Media icon in CKEditor
# User is not able to see "Edit This Media" button
moving to Needs Work.
Please refer attached screenshots for Before and After patch
Comment #16
chetanbharambe commentedComment #17
mikkmiggur commented@chetanbharambe Does your user have permission to edit that media item.
In my case when it was displayed to every editor and for every media entity it most of the cases end with the page "Permission denied".
We have allowed only to edit own media entities. That's why was needed to add permission check there, to show button only when the current user has permission to update that media entity.
Comment #19
alphex commentedI can confirm that #13 works.
The only enhancement I could possibly see is that the window thats opened to edit the media item, close, after you hit save.
Other wise, this is a huge improvement!
Comment #20
dxvargas commented#13 works for me too.
I vote this issue should be RTBC.
Comment #21
phenaproximaThanks for testing, everyone, but this is not ready for RTBC yet. There are several things that need doing:
I don't have time at the moment to explain these further, but I'll at least tag the issue for them as a sort of "to-do list".
Comment #23
Mesele29 commented#16
Comment #24
Mesele29 commentedComment #25
Mesele29 commentedComment #26
Mesele29 commented#17
Comment #27
andypostComment #28
avpadernoComment #29
ranjith_kumar_k_u commentedComment #30
ranjith_kumar_k_u commentedComment #32
blade_ukraine commentedThat is my version solving of that issue.
But to be honest I don't like to add patches like that to the core or any patches like that. And for that, I've created an extra module that provides the same functionality but in a different way.
https://www.drupal.org/project/edit_media_modal
Screenshots and video demonstration you will be able to see on the module page.
Comment #33
avpadernoComment #34
vikashsoni commentedI have applied #9 #13 and #32 patch in drupal-9.3.x-dev
But i am not able to see edit media button for ref sharing screenshot
Comment #35
blade_ukraine commentedBecause I guess You’ve edited embed image file not media. For reproduce that Issue you need at first to go to edit editor configuration and add to the toolbar the embed media button and after that You will be able to embed any enabled to embed medias via text editor.
Comment #36
akhildev.cs commentedApplied patch #32 and it's working fine, (screenshot added)
Comment #37
puddyglum@Akhildev.cs I'm also not seeing the "Edit this media". Tested using simplytest.me including the patch from #32. It's just not showing up like it is for you.
Comment #38
blade_ukraine commented@puddyglum Did you enable embed media in your CKEditor settings?
Comment #40
dealancer commentedSo when using Claro theme as an admin, Edit button is not shown correctly. Not sure if it is a patch problem or a Claro theme one.
Comment #42
slayne40 commentedSame problem for me, it seems to come from the following class:
If I remove them it works, and the button resumes a normal appearance.
Comment #43
gaurav-mathur commentedComment #44
gaurav-mathur commentedApplied patch #32 it works great.
Comment #45
smustgrave commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
@gaurav-mathur @Akhildev.cs appears screenshots were already in #34 so these were duplicated efforts unfortunately.
Hiding all the screenshot noise
Appears this was tagged for tests also which still need to happen.
I did not do a code review.
Comment #47
loze commentedWhat version of ckeditor is this supposed to work with? I do not see any edit button after applying the patch using ckedtor5
Comment #48
ericgsmith commented@loze that patch will not work with CKEditor5 as CKEditor5 does not load the form that it is altering.
I have added an MR to the edit_media_modal module with an approach for CKEditor 5 https://www.drupal.org/project/edit_media_modal/issues/3352274
Comment #49
ericgsmith commentedComment #50
dalinComment #51
dalinComment #52
jwilson3#3352274: Support CKEditor5 has been closed and marked fixed. Since this now has a working solution in contrib, should this issue re-focus efforts around inclusion of the functionality from https://www.drupal.org/project/edit_media_modal into core's Media Library CKE5 integration?
Comment #53
jwilson3I found that there is work going on elsewhere for this, including: