Problem/Motivation
When using modules that provides CKEditor plugins, such as https://www.drupal.org/project/ckeditor_font, the dependency on the module providing the plugin is not automatically added to the the editor format configuration, such as editor.editor.full_html.yml
langcode: fr
status: true
dependencies:
config:
- filter.format.full_html
module:
- ckeditor
Should be:
langcode: fr
status: true
dependencies:
config:
- filter.format.full_html
module:
- ckeditor
- ckeditor_font
- colorbutton
Proposed resolution
Add automatically a dependency on modules providing enabled CKEditor plugins.
Remaining tasks
Waiting feedback from core maintainersAgree on solution planWrite a patch- Review the patch
- Write automated tests?
- Merge the patch
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#19 | interdiff-2950795-14-19.txt | 9.3 KB | Grimreaper |
#19 | drupal-ckeditor_config_dependencies-2950795-19.patch | 8.15 KB | Grimreaper |
#14 | interdiff-2950795-6-14.txt | 2.03 KB | yogeshmpawar |
#14 | 2950795-14.patch | 4.84 KB | yogeshmpawar |
#6 | interdiff-2950795-3-6.txt | 773 bytes | Grimreaper |
Comments
Comment #2
Wim LeersWoah, great find! 👌 Thanks for reporting it so very clearly!
Of course I completely agree with the proposed resolution:
I'd love to review a patch that fixes this!
Comment #3
GrimreaperHi Wim Leers,
Thanks for your reply :).
Here is a patch that add a new method to the EditorPluginInterface so that it can be triggered to calculate the dependencies.
Currently no automated test. Waiting for the manual patch to be reviewed ok.
I found the code confusing, you constantly need to ask what "editor" means. Is it the config entity or the "editor plugin" (CKEditor, TinyMCE, etc.)
Thanks for the review.
Comment #5
GrimreaperComment #6
GrimreaperFixing Prophecy mock.
Also during my tests I have noticed some strange behavior with #2962981: File upload plugin can't be disabled, when removing buttons, config remains.
Comment #7
msankhala CreditAttribution: msankhala as a volunteer and at Material commentedExcellent work @Grimreaper. Patch looks good to me. Waiting for a review from Drupal core committer.
Comment #8
Wim LeersAdding a new method to an interface unfortunately is a BC break: https://www.drupal.org/core/d8-bc-policy#interfaces
Could you create a new
EditorPluginWithCalculatableDependenciesInterface
interface instead? That interface should be marked@deprecated
from the start, and should have a@todo Move into \Drupal\editor\Plugin\EditorPluginInterface in Drupal 9
.Comment #9
Wim LeersBTW: the patch looks great! 👌 Well done :)
Comment #10
Wim LeersThis means it's a change in
editor.module
, notckeditor.module
.Comment #11
Wim LeersPatch review:
👍
Just one nit: "pass the editor" -> "pass the text editor config entity"
s/plugin/text editor plugin/
s/roles/role config entities/
Nit: use short array notation.
Comment #12
Wim LeersHm … on second thought, this actually may make the interface change okay. Because the handful of
\Drupal\editor\Plugin\EditorPluginInterface
implementations likely all use this base class, which means disruption is super minimal.So … ignore #8!
Once the nits in #11 are addressed, I'll RTBC this, and we'll see what a core committer has to say.
Comment #13
yogeshmpawarComment #14
yogeshmpawar@Wim Leers - all suggested changes addressed mentioned in comment #11 & also added an interdiff.
Comment #15
Wim LeersThis should be reviewed by @alexpott, who is both core committer and maintainer of the configuration API. If he's okay with this, I'm okay with this.
A CR is still needed, but perhaps it makes more sense for Alex to +1 or -1 the direction before creating the CR.
Comment #16
alexpottI think the plugin should implement DependentPluginInterface no?
I'm a bit concerned that this method doesn't really have much to do with the CkEditor plugin itself and seems to be reaching out for things it itself has not configured.
This all feels quite convoluted :(
The approach seems okay but it's an API break. We should add calculateEditorDependencies to a new interface and make CkEditor implement that. And check for the interface in Editor::calculateDependenices. This way other editors won't break and get to opt in to the new functionality.
Comment #17
Wim LeersThanks for providing clear direction, @alexpott! 🙏
Comment #18
GrimreaperHello,
Thanks for the review.
I will update the patch with @alexpott suggestions.
Comment #19
GrimreaperHere is an updated patch.
Thanks for the review.
@alexpott:
The problem is that we need the Editor object in arguments to get the configuration of the Editor plugin.
Comment #20
alexpottThis is still looking really odd to me. Passing an instance of the configuration entity to the plugin is kinda the wrong direction. Plugins really should have no knowledge of a configuration entity. Looking at the code in CkEditor::calculateDependencies it is hard to reason why this goes there. However the Editor configuration entity is being passed all over the place through the editor and ckeditor plugin system so it's hard to roll that back now.
In an ideal world the Editor configuration entity is used to configure the Editor and other plugins but the plugins don't know anything about the Editor config entity this separation of concerns means that the plugins can stand on their own feet with the config system.
Atm I can't see any other way of doing this without considerable refactoring and API breaks :(
Comment #21
Grimreaper@alexpott, I completly agree with you and I had to follow the same reasonning.
Comment #23
GrimreaperHum, in my local environment I am using PHPUnit 6 and I don't have the error mentioned in comment 22.
So I don't know how to debug this failure without downgrading PHPUnit.
Comment #29
Wim LeersBecause this is a problem/oversight in the
Editor
config entity, the same problem still exists for CKEditor 5 too. Discovered this while responding to #3245720-50: [drupalMedia] Support choosing a view mode for <drupal-media>.When I started implementing this independently, I ended up doing something very similar to @Grimreaper because AFAICT there's no other way.
Each text editor config entity has its own configuration: which buttons are enabled, which settings are applied, and so on. So I don't see how this could work any other way? 🤔
I don't think this is possible for text editor config entities because the set of plugins to choose from is itself dependent on the text editor plugin being used!
IOW: there's two layers of config dependencies here:
\Drupal\editor\Entity\Editor
has a\Drupal\editor\Plugin\EditorPluginInterface
plugin configured — this is stored in the top-leveleditor
key in theEditor
config entity. In core right now this usually means theckeditor
plugin (\Drupal\ckeditor\Plugin\Editor\CKEditor
) is configured. In the future, it'll mean that usually theckeditor5
plugin (\Drupal\ckeditor5\Plugin\Editor\CKEditor5
) is configured.ckeditor
it's@CKEditorPlugin
plugins that implement\Drupal\ckeditor\CKEditorPluginInterface
; forckeditor5
it's@CKEditor5Plugin
plugins that implement\Drupal\ckeditor5\Plugin\CKEditor5PluginInterface
.Plugins for one text editor plugin do not work for another.
I don't think anything else (in Drupal core) has this multi-level plugin architecture.
I propose we generalize @Grimreaper's
DependentEditorPluginInterface
proposal into something that isn't Editor-specific. It's conceivable there are other things that need this.This is also why this comment that was added in 2014 in #2080823: Create API to discover config entities' soft dependencies and use this to present a confirm form on module uninstall is wrong:
The
Editor
entity does not have a plugin collection directly. It has a single plugin (\Drupal\editor\Plugin\EditorPluginInterface
) which may have a plugin collection. (Not every text editor plugin is required to support plugins — a simple one with far less configurability and extensibility would not need it.)Comment #30
Wim LeersIMHO this is clearly a
bug.Postponed the sibling CKEditor 5 issue on this: #3269101-11: [PP-1] Ensure enabled CKEditor 5 plugins remain available by calculating corresponding dependencies.
Comment #33
Wim LeersRelated: #3231354: [PP-1] [META] Discuss: merge the Editor config entity into the FilterFormat config entity.
Comment #35
Wim LeersThis caused problems once again — this time a detailed report by @gordon at #3335155-8: CKEditor 5 toolbar configuration: no admin UI visible, only JSON in a <textarea>.
Comment #36
Wim LeersCKEditor 4 is gone. But this problem is not.