Closed (fixed)
Project:
CKEditor 5
Version:
1.0.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
24 May 2021 at 16:42 UTC
Updated:
17 Jun 2021 at 08:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersYESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS this has confused and bothered me since day 1 🤪😬
To be clear: this totally makes sense in an MVP sense. But it's definitely something we need to fix at some point. I suspect that with #3209613: Add "Table" plugin having been merged, this has become super obvious 🤓
We basically need to expand the logic in
\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getEnabledDefinitions()(and its helper\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::isPluginDisabled()) to match\Drupal\ckeditor\CKEditorPluginManager::getEnabledPluginFiles()'s logic. In CKEditor 4 we had\Drupal\ckeditor\CKEditorPluginButtonsInterfaceto make this very explicit, but I think that @zrpnr would like to avoid that. Besides, with the metadata now living in*.ckeditor5.ymlunder atoolbar_itemskey, that would not even be necessary I think.Ironically,
from the issue summary's proposed resolution sounds almost exactly like
CKEditorPluginButtonsInterfacein Drupal 8|9 core for CKEditor 4.I am absolutely not intent on reusing the exact same interface composition architecture though. But I am really curious what you had in mind exactly.
In fact, I think that @zrpnr would want a sibling method for
::getEnabledDefinitions()and::getEnabledLibraries(). So that'd look like the attached patch basically.Looking forward to thoughts from both of you here! 😊
Comment #3
wim leersFor
We just need to modify
\Drupal\ckeditor5\AdminUi::validateAllowedElements()'s… except that already takes into account enabled plugins! So the problem is that ::getEnabledPlugins() considers all plugins enabled by default unless it implements
CKEditor5PluginContextualInterfaceand returnsFALSEfor its::isEnabled()implementation.Tests should start failing now.
Comment #4
wim leersOMG d.o you're drunk 😬
Comment #6
wim leersAlright, those failures look like they are expected!
Assigning to @zrpnr for review :)
Comment #7
wim leersThis blocks #3215597: CKEditor 5 plugin settings form available always, even when the plugin is not enabled.
Comment #8
wim leersNote that #4 is failing as expected/hoped:
(Never mind DrupalCI's broken escaping…)
… because instead of requiring all HTML elements of all available CKEditor 5 plugins to be allowed, the change in #4 causes only the HTML to be required that the actually enabled plugins need!
Comment #9
zrpnrIt is more clear to have this method, but there's no change in the result since $definitions already was filtered by the changes in isPluginDisabled which is called by getEnabledDefinitions a few lines up.
so simple! I love this, and it is such a nice way to let non toolbar providing plugins pass but disables any toolbar providing plugins IF they don't have any items in the current toolbar.
I'm really amazed at how little code is needed to make this work, manually tested and it seems to be exactly right. Image is allowed, since it does not provide a toolbar item, but any plugins like bold are removed entirely if their toolbar item is missing. With either bullet or numbered lists the List plugin is correctly enabled.
This will be greatly improved by #3201641: Improve the HTML filter configuration UX where the allowed elements for the html filter get automatically set.
Comment #11
wim leersCorrect, that was very much the intention! That's why I wrote this in #2:
🤓
I think that means you're in favor of this 😁
Soooo … let's push this to completion!
Thanks to this, one problem become apparent: it is impossible to disable the
ckeditor5.imageplugin. Because right now\Drupal\ckeditor5\Plugin\CKEditor5PluginManager::isPluginDisabled()assumes everything is enabled, unless:CKEditor5PluginContextualInterfaceand the implementation of::isEnabled()returnsFALSECurrently, only
ckeditor5.imagehits this edge case: it's the only plugin that does not implementCKEditor5PluginContextualInterfaceand has no buttons.The consequence is that the smallest set of HTML that you can enable for a CKEditor 5 instance is:
That's a regression compared to CKEditor 4: it should absolutely be possible to have imageless text formats.
In CKEditor 4, the logic is inverted. Quoting the docs of
\Drupal\ckeditor\CKEditorPluginManager::getEnabledPluginFiles():#4 proves we do not actually need a CKEditor 5 equivalent of
CKEditorPluginButtonsInterface. Yay! 🥳But it does mean that we need to figure out a solution for
ckeditor5.image. #3195965: Register CKEditor 5 plugins via YAML definitions instead of class annotations split it up in an unconditionalckeditor5.imageand a conditionalckeditor5.imageUpload(see https://git.drupalcode.org/project/ckeditor5/-/merge_requests/6/diffs?co...). That was only possible because until this very issue, this module would always require the HTML for all CKEditor 5 plugins, regardless of which ones would be used. Specifically see #3195965-4: Register CKEditor 5 plugins via YAML definitions instead of class annotations.We can't just conditionally enable
ckeditor5.imagethough, because if there's no PHP code, one cannot implementCKEditor5PluginContextualInterfaceeither. So I see at least 4 solutions:elementsannotation fromckeditor5.imagetockeditor5.imageUpload.ckeditor5.imageandckeditor5.imageUploadinto a single plugin definition again. This is also still very simple. It would just mean one fewer CKEditor 5 plugin definition defined in YAML.classtockeditor5.imageand add a tiny amount of code to implementCKEditor5PluginContextualInterface.enableIfToolbarItemIsPresent: foobar. This is an API addition though. It feels a bit logic-y. Which is bad for an annotation.I think option #3 most closely aligns with the current architecture and intent. So went ahead and implemented that. See https://git.drupalcode.org/project/ckeditor5/-/merge_requests/42/diffs?c....
Comment #12
wim leersI just advocated against
… but I actually do think this could be a good idea. Because it will actually allow writing less PHP code. Don't want to derail this issue though. So created #3216244: Remove CKEditor5PluginContextualInterface and CKEditor5PluginContextualValidationInterface in favor of annotation.
Comment #13
wim leersActually, there's no reason this needs to be postponed… 😅
Comment #14
wim leersI cannot debug any of the remaining test failures because
FunctionalJavascripttests refuse to run on my machine currently. Do not want to redo my development environment just for this issue on a Friday 😬🙈Comment #16
bnjmnm@Wim Leers walked me through this. While reviewing the MR after the walkthrough, it was apparent how to address the test failures, which I did in this commit.
CKEditor5PluginManagerTest::testEnabledPluginsWas failing because it was testing for default enabled plugins, and Essentials was not listed. Because the Essentials plugin is always enabled as a result of itsisEnabledmethod always returning TRUE, I knew it was safe/correct to add this to the array of expected plugins to be enabled by default. I also added the following comment inCKEditor5.phpto explain why essentials or other "always-on" plugins can show up as default plugins even if they aren't part ofdefaultSettings()CKEditor5FormatValidationTest::testHtmlFilterValidationwas failing as there were expected strings that needed to be changed. The expected default value ofallowed_htmlstill needs to be<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id>, which is the default value defined by the Filter definition. (this value will change in #3201641: Improve the HTML filter configuration UX but not here). The$allowed_elementsstring also needed to be updated as it now only includes tags/attributes defined by the default plugins. Previously, it included the tags/attributes defined by EVERY plugin, whether or not they were enabled.Comment #17
wim leersI see @bnjmnm removed
from the issue summary in #16.
I agree with that, because without this being committed, #3201641: Improve the HTML filter configuration UX will not actually be able to test the full breadth of what it needs to do. Right now, #3201641: Improve the HTML filter configuration UX will always generate one and the same configuration. But we actually need it to change whenever the filter settings change (that's the critical bug I just found and reported at #3201641-18: Improve the HTML filter configuration UX). Once this issue lands, we will also need it to change whenever the set of toolbar items in CKEditor 5 toolbar changes. It'd be better to tackle all that simultaneously.
So I'd love to land this ASAP.
Comment #18
wim leers@lauriii confirmed to me that that last nit of his was the only remaining blocker. Marking RTBC in anticipation of tests coming back green.
Comment #20
wim leers