Problem/Motivation
Discovered while reviewing #3245720: [drupalMedia] Support choosing a view mode for <drupal-media>.
#3245720: [drupalMedia] Support choosing a view mode for <drupal-media> made <drupal-media data-view-mode>
an essential part of the media integration.
But in the issue where the MediaEmbed
filter was introduced #2940029-97: Add an input filter to display embedded Media entities.
This also explains why SmartDefaultSettingsTest
was failing in https://git.drupalcode.org/project/drupal/-/merge_requests/1796/diffs?co... because it did not expect the data-view-mode
attribute to be added to the result of the CKEditor 4 → 5 upgrade path.
Proposed resolution
- Make
<drupal-media data-view-mode>
a separate array value inmedia_media
'sdrupal.elements
- Add a configuration UI for the CKEditor 5 media plugin: a checkbox that indicates whether content creators are allowed to override the default view mode
- Implement
\Drupal\ckeditor5\Plugin\CKEditor5PluginElementsSubsetInterface
, to respect the configuration added in step 2, and hence unset the<drupal-media data-view-mode>
when that checkbox is not checked - Add a case for
media_media
to\Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core::computeCKEditor5PluginSubsetConfiguration()
, to generate the correct configuration during the upgrade path. - Add an extra test case to
SmartDefaultSettingsTest
, to test a variation of$basic_html_format_with_media_embed
: one that has<drupal-media data-view-mode>
allowed as well. - Add a validation constraint (see #7) to ensure that the
media_embed
'sallowed_view_modes
setting is in sync with themedia_media
CKE5 plugin's new setting.
Remaining tasks
See proposed resolution.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#30 | 3269657-30.patch | 43.51 KB | lauriii |
| |||
#20 | Screenshot 2022-04-28 at 15.23.49.png | 651.09 KB | Wim Leers |
#11 | Screen Shot 2022-04-21 at 4.33.19 PM.png | 298.95 KB | hooroomoo |
#7 | Screenshot 2022-04-20 at 14.19.02.png | 127.61 KB | Wim Leers |
Issue fork drupal-3269657
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:
- 3269657-pp-1-drupalmedia-the changes, plain diff MR !2079
Comments
Comment #2
Wim Leers(Documenting the thinking I've done around this.)
Clarification: we should match the logic and spirit in #3074608: Optionally allow choosing a view mode for embedded media in EditorMediaDialog. Prior to that,
data-view-mode
was an attribute required to be allowed. That's essentially what #3245720: [drupalMedia] Support choosing a view mode for <drupal-media> is doing too.That means that
<drupal-media data-view-mode>
should be enabled whenever >=2 options are selected inmedia_embed
filter plugin'sallowed_view_modes
setting.The existing CKEditor 5 plugin conditions (
toolbarItem
,imageUploadStatus
,filter
,requiresConfiguration
,plugins
) cannot express this.This is why the suggested solution in the IS says:
… but this would sort of be duplicating the logic in
\Drupal\media\Plugin\Filter\MediaEmbed::settingsForm()
.The reason this is so tricky? Because the filter settings are de facto also the editor settings in this case:
(That is literally referring to
EditorMediaDialog
, which CKEditor 5 won't use!)We cannot even create a new
requiresFilterConfiguration
which would be similar torequiresConfiguration
(which operates on this CKEditor 5 plugin's configuration) because it cannot be expressed using that.The best we can do really is to do what is outlined in the current plan in the issue summary, and use the same approach that #3224652: [drupalImage] Add ckeditor5-image's imageresize plugin to allow image resizing used: a new piece of configuration.
Comment #5
Wim LeersComment #6
hooroomooComment #7
Wim LeersI wrote this in the proposed resolution roughly a month ago:
… but I failed to realize that this is basically duplicating configuration stored by the
media_embed
filter's settings:Then again, that is pretty weird too: the filter settings dictate if the text editor should offer the user the choice. Even though filters are supposed to not be aware of Text Editors at all. This is of course independent of CKEditor 5 work — this is pre-existing and works in CKEditor 4.
Conclusion:
allow_view_mode_override
setting for the Media CKE5 plugin is in fact in sync with the filter settings. This requires adding an additional validation constraint that is able to inspect both theEditor
config entity and theFilterFormat
config entity. To help you get started:→ this should basically work, but it really should be A) moved into a new validation constrain validator, B) that constraint should be added to
ckeditor5.pair.schema.yml
and C) this needs test coverage in\Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::providerPair()
. Start with C: add a test that should throw a validation error for the configuration not being in sync. Then adding it will make the MR green 👍Updated issue summary accordingly.
Comment #8
hooroomoo1. How do I add the behavior of the Media settings plugin tab disappearing and reappearing in the plugin settings when the drupal media toolbar item is active/inactive? Is that done through the "toolbar_items" property in the ckeditor5.ckeditor5.yml file? If so when I added it to media.media it didn't work and there is flickering when I make drupal media toolbar item inactive/active.
2. The view modes I added to my ['VALID: allow_view_mode_override condition met: filter must be configured to allow 2 or more view modes'] test case in ValidatorsTest.php aren't being added so the test is failing. I am not sure why they are not being added correctly.
Comment #9
Wim Leers#8:
media_embed
filter is active. When that filter is active, media can be embedded. Which also means the filter's default view mode can be overridden.The button you're referring to is the button. That button is not required to be able to embed media — it merely offers a better UX for embedding media (using the media library).
(I get that this is a bit odd, but it's the separation of concerns that Drupal core has, and so we must respect it too. The easiest way to observe this: uninstall the Media Library module. The Media Embed filter can still be enabled, and you can still override the view mode. There literally is no Media Library available. Lots of Drupal 8 sites are using Media without Media Library, because the latter was only added after the Media module was added and stabilized!)
In other words: nothing left to be done here! 😄
So all that remains here now is updating a bunch of tests to ensure that their CKEditor 5 configuration no longer violates the new validation constraint! 🥳
Comment #10
Wim LeersYay, 252d1ffb fixed the
ValidatorsTest
failures 👍I also took a look at the
SmartDefaultSettingsTest
failure and provided pointers for that on the MR just now.Comment #11
hooroomoo1. I configured two view modes in setUp() in Drupal\Tests\ckeditor5\FunctionalJavascript\MediaTest but the editor fails to initialize in every test. @lauriii found out today that some configurations of allowed view modes cause CKE to fail to initialize. So it might be related to that. We are planning to meet tomorrow about that.
2. In Drupal\Tests\ckeditor5\FunctionalJavascript\AdminUiTest::testPluginSettingsFormSection I am not sure why the media plugin is enabled when the media_embed filter is disabled.
Comment #12
Wim LeersAlmost there, a few more failures to fix :)
#11:
I'm pretty sure it's the case of configuring the
media_embed
filter to either A) less than two view modes (which the filter happily accepts because it unfortunately lacks sufficient validation logic), B) the two view modes do not exist for all media types, but only for some media types. So when editing media of a type for which <2 of the allowed view modes are allowed, the editor crashes.Neither of those are bugs on our end; they're both bugs in the
media_embed
filter's logic. That should not block this issue.Comment #13
Wim Leers#3276627: CKEditor5::shouldHaveVisiblePluginSettingsForm() does not correctly handle configurable CKE5 plugin that has a filter condition is now ready for review.
Comment #14
Wim Leers#11.2 means this issue is blocked on #3276627: CKEditor5::shouldHaveVisiblePluginSettingsForm() does not correctly handle configurable CKE5 plugin that has a filter condition.
Also, let's make it more clear that this is a highly important issue: a CKEditor 5 stable blocker.
Comment #15
hooroomooNote: remove TODO's in this issue from #3276627: CKEditor5::shouldHaveVisiblePluginSettingsForm() does not correctly handle configurable CKE5 plugin that has a filter condition
Comment #16
Wim Leers#3276627: CKEditor5::shouldHaveVisiblePluginSettingsForm() does not correctly handle configurable CKE5 plugin that has a filter condition landed! That means this is unblocked, and this needs a rebase.
Comment #17
hooroomooComment #19
nod_rerolled the patch after #3261599: Use CKEditor 5's native <ol start> support (and also support <ol reversed>) made it in, looks good but not familiar enough to RTBC.
Comment #20
Wim Leers#3261599: Use CKEditor 5's native <ol start> support (and also support <ol reversed>) landed earlier today and modified
\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getProvidedElements()
. It introduced a bug that only is exposed by this plugin so far:The root cause:
HtmlRestrictions::fromString('<tag foo> <tag bar>')
will only actually parse the last of the two tags. Which is not entirely unreasonable.Simple work-around: don't declare multiple identically named tags within one plugin's
elements
metadata:Beyond that, we now need to update the test expectations here slightly because
<ol type>
no longer needs to be supported throughSourceEditing
— we get native support for it now 👍Soooooooo close! 😅😅😅😅
Comment #21
Wim LeersOne failure, but unrelated. Re-testing.
Two more remarks: one about the labels being wrongly hardcoded, the other about needless code complexity 🤓
Comment #22
hooroomooComment #23
Wim LeersComment #25
lauriiiPosted few comments on the MR.
I'm still wondering why are we adding the additional plugin configuration for view modes? I thought we could rely on the embed media configuration and enable the attribute based on whether view modes are configured by the embed media filter or not. Could we document the rationale for the current solution in the issue summary?
Comment #26
Wim LeersThe rationale is documented in #7.
Curious about your thoughts :)
Comment #27
lauriiiThat helps explain the rationale for #25.
Moving back to get feedback on MR addressed.
Comment #28
Wim LeersResponded on the MR!
Comment #29
Wim LeersI previously RTBC'd this in #23, then again in #26. I just added a trivial fix for @lauriii's remark.
Back to RTBC :)
Comment #30
lauriiiComment #34
lauriiiCommitted 32bf036 and pushed to 10.0.x. Cherry-picked to 9.5.x and 9.4.x. Thanks!
Consulting release managers on whether this could be committed to 9.3.x given that this introduces a post update hook.Was reviewing other CKEditor 5 issue in parallel which included a post update hook. This one does not include a post update hook and I think could be backported to 9.3.x after the freeze ends.
Comment #37
bnjmnmCherry picked to 9.3.x now that the freeze has ended.