Problem/Motivation
We found two bugs related to #3245720: [drupalMedia] Support choosing a view mode for <drupal-media>. The first is a big bug, the second is also a bug but more of an edge case than the first bug and it is preexisting in CKEditor 4 as well.
1. In the embed media filter setting inside the editor configuration, when a user sets the default view mode as something that is NOT checked off as a selectable view mode, the editor fails to initialize because it throws a Javascript error. Although this is due to a prexisting bug in media, a temporary workaround will be added in this issue to prevent the editor from crashing. #3277049: "Embed media" filter allows invalid config of default view mode not being part of view modes selectable was created to fix the preexisting bug.
2. When the user sets a default view mode as a view mode that is not allowed for a certain bundle, it applies that view mode to the element anyway. In my screenshot below, I configured my document media type so that "tiny" view mode is not allowed. However as you can see in the source code, it has "tiny" on the element. (Below screenshot is CKEditor 5 but same thing happens for CKEditor 4). Assuming that this is a preexisting problem with the media module, #3277244: media_embed filter: a default view mode that isn't allowed for a media type gets applied anyway was created for this.
Steps to reproduce
Bug 1:
1. Go to your CKEditor 5 configuration
2. Enable Embed media
3. Select something as the Default view mode
4. Do not check that view mode in the "View modes selectable in the 'Edit media' dialog section
5. Return to editor (editor should fail to load, you should see error in console)
Bug 2:
1. Go to /admin/structure/media/manage/document/display (or whatever media type)
2. In Custom display settings, do not check whatever view mode you want to test with.
3. Go to your editor configuration and under embed media, set the Default view mode to that view mode from #2.
4. Go to your editor and insert a document and check the source code of that element and you should see the view mode that should not be allowed.
Proposed resolution
For Bug #1 come up with a workaround either on the client side or on the PHP side if it is possible. One idea is to force add the Default view mode into the list of drupal element styles on the client side if it is not checked in "view modes selectable in the 'Edit media' dialog.
Another idea is to prevent the editor config from saving if the default view mode is not checked and show an error on the editor page telling the user.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
Screen Shot 2022-04-22 at 11.23.03 AM.png | 104 KB | hooroomoo | |
Screen Shot 2022-04-22 at 11.12.10 AM.png | 96.22 KB | hooroomoo |
Issue fork drupal-3276670
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
Comment #2
hooroomooComment #3
hooroomooComment #4
hooroomooComment #5
Wim LeersAFAICT
\Drupal\media\Form\EditorMediaDialog::buildForm()
also only allows selecting the selected view modes, with no fallback behavior to automatically include the default view mode. Which makes no sense. In other words: the validation logic of\Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()
is inadequate. Therefore this is a bug in themedia
module, and deserves a separate issue there.In other words: I agree with your proposed solution.
Let's move bug 1 into a new issue, so we can keep this issue for bug 2, for which there is less clarity so far.
What's the behavior of this when using CKEditor 4? I think you're saying it's the same problem?
More importantly: how does this behave in the filter itself, without considering either CKEditor 4 or 5? Looking at
\Drupal\media\Plugin\Filter\MediaEmbed::process()
, I don't think it's taking into account that the view mode may not exist for the bundle (MediaType
). So that'd be another bug in themedia
module, not in the CKEditor 5 module.Comment #6
Wim LeersTo clarify:
ckeditor5.module
.ckeditor5.module
component issue.ckeditor5.module
component makes sense. Still, it's important that bug/issue 1 gets created first, because then the hardening in the CKEditor 5 module's JS will be able to point to that issue to justify hardening against an edge case that should not exist.Comment #8
hooroomooComment #9
hooroomooCreated https://www.drupal.org/project/drupal/issues/3277049 for Bug #1
Comment #10
Wim Leers#9: Thanks — now just needs one more follow-up for bug #2 👍
The test coverage looks great! Zero remarks 🤓
Comment #11
hooroomooComment #12
hooroomooCreated https://www.drupal.org/project/drupal/issues/3277244 for bug #2
Comment #13
hooroomooUpdated issue summary with the two new media issues.
Comment #14
nod_Followups have been created, and crash is fixed.
Comment #17
catchCommitted/pushed to 10.0.x, cherry-picked to 9.4.x and 9.3.x, thanks!