Problem/Motivation

With UI Patterns 2.0, we cover most of the Drupal Core display builders:

  • ui_patterns_blocks: Block Layout, Layout Builder ....
  • ui_patterns_layouts: Layout Builder, Field Layout...
  • ui_patterns_field_formatters: Manage Display, Layout Builder, Views...
  • ui_patterns_views: Views

However, one is still missing: Ckeditor5.

There is already a module to use Layout plugins in Ckeditor5: https://www.drupal.org/project/ckeditor_layouts
However:

Proposed resolution

We can take inspiration from UI Icons module

Contrib:

Preview:

  • The modal is placing a placeholder (<drupal-icon data-icon-id> in UI Icons) in the Ckeditor virtual DOM with all the component configuration (component id, variant, slots, props)
  • An HTTP controller is generating the preview using the Render API

Rendering:

  • A text filter plugin is catching the place holder and rendering the HTML using the
  • render API

Configuration:

  • in the text format configuration page, in the CKEditor 5 plugin settings, we can chose the components we want to expose like that

https://git.drupalcode.org/project/ui_icons/-/tree/1.0.x/modules/ui_icon...

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

pdureau created an issue. See original summary.

christian.wiedemann’s picture

Maybe we can use CKEDitor Block integration https://www.drupal.org/project/ckeditor_insert_blocks

just_like_good_vibes’s picture

we should test this :)

juc1’s picture

By the way this doc page https://www.drupal.org/docs/develop/theming-drupal/using-single-director... says:

UI Patterns (version >=2.0) - Automatically integrates components into Drupal within Layout Builder, CKEditor, Views, Blocks, etc.

So does that mean the doc is misinforming because UI Patterns does not work with CKEditor?

just_like_good_vibes’s picture

Hello juc1, thank you for this kind message ;)
we will soon propose a tiny update to this part of doc, if a small mistake has been made by someone.
we don’t want any misunderstanding, indeed ckeditor integration had been planned for 2.1, and not for 2.0.

juc1’s picture

@just_like_good_vibes ok merci.

pdureau’s picture

It is like that since the first version of SDC documentation, nearly 2 years before the release of UI Patterns 2: https://www.drupal.org/node/3352957/revisions/13043240/view 🙃

The scope of the future 2.0 and 2.1 versions was far from being defined at this time. I will fix this.

just_like_good_vibes’s picture

Assigned: Unassigned » just_like_good_vibes

let's go

yannickoo’s picture

Hey @just_like_good_vibes! I would recommend to use the Embedded Content module and provide a way to provide plugin derivatives for all SDCs.

Here you can find an example implementation of an Embedded Content plugin.

just_like_good_vibes’s picture

Hello @yannickoo and thank you for the tip.
Indeed, we target something similar to what Embedded Content is doing, but first we are trying to have no contrib dependencies.
We will anyway discuss that potential dependency with others from the team.
We have already ckeditor5 implementations in ui_styles an ui_icon module, so we can add one here.

yannickoo’s picture

Hello again 👋 I wanted to share the minimal plugin implementation based on Embedded Content module ➡️ #3549147: [2.1.0] Embedded Content plugin.

Even if we don't want to introduce new dependencies I think that can be helpful for people so they could already place components in CKEditor.

just_like_good_vibes’s picture

Title: [2.1.0] Add Ckeditor5 integration » Add Ckeditor5 integration

i made some advanced on this. for the moment i am trying to make it work,without the context.

just_like_good_vibes’s picture

it is work in progress, but i am approaching something :))
anybody wants to give a try?

just_like_good_vibes’s picture

Status: Active » Needs work

just_like_good_vibes changed the visibility of the branch 3474134-ckeditor to hidden.

just_like_good_vibes changed the visibility of the branch 3474134-2.1.0-add-ckeditor5 to hidden.

sonfd’s picture

After applying the patch, my CKEditor toolbar fails to load and I get a console error:

CKEditorError: plugincollection-soft-required {"missingPlugin":"WidgetToolbarRepository","requiredBy":"ComponentEditing"}
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#erro...

Drupal 11.3.5, UI Patterns 2.0.15

just_like_good_vibes’s picture

hello, thank you @sonfd for testing the code in the MR.
we will get back to this old proposition and correct.

just_like_good_vibes changed the visibility of the branch 3474134-ckeditor-202511 to hidden.

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Needs work » Needs review

hello there,
I managed to spend some time (finally!) on the ckeditor5 sub-module.
it looks great now, someone wants to test and review?
thank you in advance

just_like_good_vibes’s picture

comment #19 from @sonfd : the problem is Fixed, thanks for the report. The plugin declared WidgetToolbarRepository as a soft requirement, which only works on text formats where another plugin (image, media) loads it. The new MR carries it as a hard requirement.

The new MR refreshed the existing work on a fresh 2.0. (replacing the previous MR !468).
- Insert, edit and delete component in ckeditor;
- the dialog opens a large window, showing the component form and the edited component.
- the entity of the edited text is injected in the context (youhou!)
- Kernel, Functional and Playwright tests.

We cannot configure yet which components may be embed in a given text format, that feature would need follow-up issue.

pdureau’s picture

Assigned: Unassigned » pdureau

Sounds great. I will have a look.

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs review » Needs work

Tested on local env. It is impressive:

  • context injection in sources (with fake temp entity when the entity is not created yet)
  • draggable, copy/cut/pastable, components
  • editable components

Issues:

  • Infinite recursion and memory limit when we inject the WYSIWYG field we are currently editing in a component slot. I guess we have similar inifinite loop with 2 or more WYSIWYG embedding each others.

That's all for now

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » pdureau
Status: Needs work » Needs review

This recursion problem is wider than ckeditor5 integration. we will create a separate issue for that :)

pdureau’s picture

Assigned: pdureau » just_like_good_vibes
Status: Needs review » Reviewed & tested by the community

OK for me.

Do you want to fix the little stylelint warnings or are we good?

just_like_good_vibes’s picture

Assigned: just_like_good_vibes » Unassigned
Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.