Problem/Motivation

It is not possible to embed multiple media items into CKEditor in one shot; you can only embed one at a time. This was deliberately done for multiple reasons. Here are a few extracted from comment #6:

  • If we select multiple items to embed at once, what order should they be embedded in?
  • How would people be able to re-order them?
  • How would we make this accessible?
  • How would we make it usable and intuitive to users?

Proposed resolution

Unclear, but if we want this feature, it's going to need answers to the above questions, plus any others that come up in the process of building this.

Remaining tasks

Figure out if we want this feature
Validate it with the UX team and accessibility maintainers
Create a patch with tests
Get subsystem maintainer sign-off
Get sign-off from the UX team
Get sign-off from the accessibility maintainers
Commit

User interface changes

TBD

API changes

TBD

Data model changes

Unlikely, but TBD

Release notes snippet

TBD

Issue fork drupal-3129235

Command icon 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

OCTOGONE.dev created an issue. See original summary.

joseph.olstad’s picture

Project: D7 Media » Drupal core
Version: 8.x-1.x-dev » 10.0.x-dev
Component: Media WYSIWYG » media system
cilefen’s picture

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

Features can go into 9.1.x.

OCTOGONE.dev’s picture

Issue summary: View changes
hardik_patel_12’s picture

StatusFileSize
new954 bytes

Embedding media with CKEditor is selecting only 1 media item , this because in core/modules/media_library/src/Plugin/CKEditorPlugin/DrupalMediaLibrary.php file in getConfig(Editor $editor) function

$state = MediaLibraryState::create(
      'media_library.opener.editor',
      $media_type_ids,
      reset($media_type_ids),
      1,
      ['filter_format_id' => $editor->getFilterFormat()->id()]
    );

media_library_remaining is hardcoded to 1 , i don't know this is intentionally hardcoded or not .

Suppose if user wants to upload multiple image then system will not gone allow, so instead of hardcoding to 1 we can set unlimited value for media_library_remaining so user can select images on the basis of their choice.

phenaproxima’s picture

Issue tags: -ckeditor, -media

CKEditor was limited to one embed for an excellent reason: allowing multiple embeds at once introduces several UX- and accessibility-related complications. For example, what order should the items be inserted? If we want to allow people to re-order them (and we obviously should), how would that work, and would it make sense to users? Would it be accessible? If not, how would we make it accessible?

Allowing only one embed bypassed all of these issues, allowing us to deliver the basic feature on time in Drupal 8.8. I'm not saying we could never have the ability to embed multiple items at once, but we'd have to think it through very carefully first.

phenaproxima’s picture

Issue tags: +Usability
aaronmchale’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

Added issue summary template, actual content needs updated though.

aaronmchale’s picture

Title: Make possible to select Multiple media when Embedding media with CKEditor » Allow embedding multiple Media Entities using the Media Library in CKEditor

Better title.

phjou’s picture

I discovered the same issue.

I strongly disagree with the statement:
"selecting multiple media of different type doesn't make sense"

In my case I wanted to create my own ckeditor plugin based on the one from Media. It is to create a gallery and it is supposed to show images or videos.

phenaproxima’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

I strongly disagree with the statement:
"selecting multiple media of different type doesn't make sense"

The problem is not selecting media of different types -- that bit makes perfect sense. The problems arise when trying to embed multiple media items, regardless of type, for some of the reasons I outlined in #6. I have updated the issue summary accordingly.

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.

jidrone’s picture

This is my opinion regarding the concerns:

If we select multiple items to embed at once, what order should they be embedded in?
I think for most of the users it doesn't matter as long as they are able to reorder them.

How would people be able to re-order them?
Currently, the media items are already draggable in the CKEditor, maybe we can make the draggable icon more prominent and easier to click.

How would we make this accessible?
I think the previous point will resolve this

How would we make it usable and intuitive to users?
I think if the user can select as many items as they want, then if all of them are stacked when inserted on the editor it is intuitive.

jidrone’s picture

Status: Active » Needs review
benjifisher’s picture

StatusFileSize
new418.16 KB

We discussed this issue at the end of #3208186: Drupal Usability Meeting 2021-04-23. We agreed that this is a useful change.

As far as usability is concerned, the main thing we would like to see is an easier way to rearrange things in CKEditor. There is a "handle" with the hover text "Click and drag to move", but in my brief test it did not work. But fixing that is a problem for CKEditor and/or its integration with Drupal. That is not a blocker for this issue.

The plan is to make CKEditor 5 the default for Drupal as soon as we can (probably in Drupal 10). There is already a contrib module CKEditor 5. I think it would be interesting to see whether that helps with this issue.

Here is a screenshot showing the "handle":

Widget in CKEditor window with hover text "Click and drag to move"

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.

sleopold’s picture

The patch above lets you upload multiple media entities at once, but still only lets you insert one at a time. The following patch will let you upload and insert multiple. As mentioned above, the UI isn't great once they're in, but there is a handle to drag things around.

sleopold’s picture

StatusFileSize
new4.98 KB
sleopold’s picture

StatusFileSize
new4.98 KB
jidrone’s picture

Hi @sleopold,

The fix including test is in the Merge Request.

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.

4kant’s picture

The patch in #21 works well for me.

ranjith_kumar_k_u’s picture

StatusFileSize
new4.85 KB
new1.75 KB

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.

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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.

mayurngondhkar’s picture

StatusFileSize
new4.95 KB

Reroll patch

mayurngondhkar’s picture

jopdebeeck’s picture

StatusFileSize
new85.12 KB

We required this feature when upgrading to Drupal 10.1.2.

I rerolled the patch for use in drupal 10.1.x

Patch might not apply for 10.1.2 specifically. In that case, checkout the 10.1.2 core tag, apply the patch and if the hunk on
drupalMedia.js fails to apply, you can skip that and remake the patch after running yarn in the core folder:

cd core
yarn install
yarn build:ckeditor5

_utsavsharma’s picture

StatusFileSize
new1.65 KB
new85.09 KB

Fixed failures in #32 for 10.1.x.

glenndw’s picture

StatusFileSize
new86.5 KB

The previous patch had a problem when adding media.

4kant’s picture

#34 doesn´t apply any more after update from drupal 10.1.4 to 10.1.5
Thanks!

jopdebeeck’s picture

StatusFileSize
new85.27 KB

#35
Rerolled the patch for 10.1.5

vsujeetkumar’s picture

@GlennDW Interdiff should be there in #34, It's help others to understand the changes you have done.
@jOpdebeeck diff required while we rerolling. Please check the doc.

glenndw’s picture

StatusFileSize
new7.68 KB

Rerolled the patch for 10.2.3

jhandsta’s picture

@vsujeetkumar Interdiffs on re-rolls are usually not really required, because only the patched context should be different on a re-roll and not the changes themselves.
That said, there were some issues with the last patch, so in this case an interdiff could indeed be useful :)

glenndw’s picture

Rerolled the patch for 10.2.8

wannesdr’s picture

StatusFileSize
new85.26 KB

And a reroll for Drupal version 10.3.5 as well.

loze’s picture

Can someone reroll this for 10.4.1 ?

mahde’s picture

And a reroll for Drupal version 10.4.4!

loze’s picture

Can someone roll it for 10.5?

mrinalini9 made their first commit to this issue’s fork.

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new7.17 KB

Please ignore #47 merge request.
Here is the patch rerolled for 10.5.x, please review it.
Thanks!

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new89 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

e0ipso’s picture

StatusFileSize
new1.18 KB

This is the patch I am using in one of our Drupal installs running Drupal 10.4.7.

Oops. I uploaded the wrong thing.

e0ipso’s picture

loze’s picture

The patch intended for 10.5 in #47 applies but did not work for me. Does someone have one?

I got this error

ajax.js?v=10.5.4:1143 An error occurred during the execution of the Ajax response: CKEditorError: Cannot convert undefined or null to object
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-Cannot convert undefined or null to object
loze’s picture

Anyone?

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.

jhandsta’s picture

The previous patch (in #48) was missing the built JS, causing the error in #54.
Here is a re-roll for Drupal 11.3.3.

glenndw’s picture

Re-roll for Drupal 11.3.7