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.

Comments

Murz created an issue. See original summary.

murz’s picture

Here 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.

phenaproxima’s picture

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

chris matthews’s picture

Status: Active » Needs review
chris matthews’s picture

It looks like the Media Library Edit module provides a similar solution. I do think this functionality should be included in Core's media system.

danny englander’s picture

I 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.

abhijith s’s picture

StatusFileSize
new15.37 KB
new180.16 KB

Applied patch #2 on 9.2.x and it works fine.Adding screenshots below.

Before patch:
before

After patch(The edit media button appears):
after

But there is some CS issues with this patch.Needed to fix that.

 227 | ERROR   | [x] The first index in a multi-value array must be on a new line
 231 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
abhijith s’s picture

StatusFileSize
new703 bytes

Fixed the CS issue.

sulfikar_s’s picture

Hi, 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.

4kant’s picture

Thanks for #9. Works great!

mikkmiggur’s picture

StatusFileSize
new766 bytes

#9 patch works.
I added an access check, the link will be displayed only when the user has access to edit this media entity.

kishor_kolekar’s picture

StatusFileSize
new780 bytes
new796 bytes

patch #12 Apply Failed.
Added new patch please review.

gauravvvv’s picture

StatusFileSize
new99.46 KB

After applying patch #13, Edit this media field is not showing.

Adding screenshot for ref.

chetanbharambe’s picture

Assigned: Unassigned » chetanbharambe
StatusFileSize
new354.26 KB
new381.63 KB

Verified 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

chetanbharambe’s picture

Assigned: chetanbharambe » Unassigned
Status: Needs review » Needs work
mikkmiggur’s picture

@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.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

alphex’s picture

I 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!

dxvargas’s picture

#13 works for me too.
I vote this issue should be RTBC.

phenaproxima’s picture

Thanks for testing, everyone, but this is not ready for RTBC yet. There are several things that need doing:

  • Extensive automated tests
  • Review and sign-off from the usability team
  • Review and sign-off from the accessibility team

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".

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Mesele29’s picture

Version: 9.4.x-dev » 9.3.x-dev
StatusFileSize
new6.18 KB

#16

Mesele29’s picture

Version: 9.3.x-dev » 9.2.x-dev
Mesele29’s picture

Mesele29’s picture

andypost’s picture

Version: 9.3.x-dev » 9.4.x-dev
avpaderno’s picture

Status: Needs work » Needs review
ranjith_kumar_k_u’s picture

StatusFileSize
new4.81 KB
new3.08 KB
ranjith_kumar_k_u’s picture

StatusFileSize
new4.79 KB
new1.6 KB

Status: Needs review » Needs work

The last submitted patch, 30: 3168868-30.patch, failed testing. View results

blade_ukraine’s picture

StatusFileSize
new10.6 KB

That 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.

avpaderno’s picture

Status: Needs work » Needs review
vikashsoni’s picture

StatusFileSize
new68 bytes
new68 bytes

I 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

blade_ukraine’s picture

Because 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.

akhildev.cs’s picture

StatusFileSize
new41.48 KB
new35.16 KB

Applied patch #32 and it's working fine, (screenshot added)

puddyglum’s picture

@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.

blade_ukraine’s picture

@puddyglum Did you enable embed media in your CKEditor settings?

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dealancer’s picture

StatusFileSize
new42.59 KB

So 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.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

slayne40’s picture

Same problem for me, it seems to come from the following class:

  • 'js-media-library-edit-link'
  • 'media-library-edit__link'

If I remove them it works, and the button resumes a normal appearance.

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
StatusFileSize
new2.14 KB
new4.09 KB

Applied patch #32 it works great.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This 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.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

loze’s picture

What version of ckeditor is this supposed to work with? I do not see any edit button after applying the patch using ckedtor5

ericgsmith’s picture

@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

ericgsmith’s picture

Related issues: +#3352274: Support CKEditor5
dalin’s picture

Issue summary: View changes
dalin’s picture

Title: Allow edit Media items from Media Library modal dialog in CKEditor » Allow editing Media items directly from CKEditor
jwilson3’s picture

#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?

jwilson3’s picture

I found that there is work going on elsewhere for this, including:

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.