Removing all buttons from the toolbar should not be considered an error

Created on 21 January 2022, over 2 years ago
Updated 13 July 2023, 12 months ago

Problem/Motivation

When you remove all buttons from the CK Editor 5 toolbar, \Drupal\ckeditor5\Plugin\Editor\CKEditor5::validateConfigurationForm (line 529) sets a form error: 'Invalid toolbar value.' Of course an empty toolbar isn't very useful, but I do not think we should call it an error. It can be a perfectly logical in-between state while editing the toolbar. There even might be (temporary) reasons to save such an empty toolbar, but a validation error makes that impossible.

Steps to reproduce

  • Add a new text format
  • Select CK Editor 5
  • Drag all buttons off the toolbar until it is empty
  • The error will now appear

Proposed resolution

In the validate function, where it checks if there are any toolbar items, return like we do now, but do not set a form error:

    if (!$toolbar_items) {
      return;
    }

I'm not sure if this even needs tests, but I suppose we could add a test in \Drupal\Tests\ckeditor5\FunctionalJavascript\AdminUiTest that removes all buttons and asserts there are no form errors on the page. In fact, such a test could easily be integrated in the test that's waiting for approval in #3259443: Plugin settings do not appear when a configurable plugin is added AFTER removing all buttons .

Remaining tasks

Fix.

User interface changes

none

API changes

none

Data model changes

none

Release notes snippet

not needed

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
CKEditor 5 

Last updated about 6 hours ago

Created by

🇳🇱Netherlands marcvangend Amsterdam

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Closed 🐛 When a textformat has no text-editor configured ckeditor crashes Closed: duplicate as a duplicate of this. Crediting @tim@lammar.be for that!

    Clearly, a tiny percentage of people want to configure CKEditor 5 in a way that there's no toolbar at all. @tim@lammar.be, can you please explain what your use case is for:

    When you have a text format where you don't want a toolbar and you configure the text-editor field to be none, […]

    ?

    Thanks! 🙏

  • 🇧🇪Belgium Tim Lammar

    @Wim Leers,
    Sure :-)
    Our use case is we have a text format field and 2 form modes for content editing of that specific node type.
    In one form mode, the field may be filled with content generated by editor buttons. In the other form mode, the same field may only be filled with text (much like a textarea field). This is mostly because the one form mode is used for users with more permissions, like using advanced editor functionality. The other form mode is used for users with less permissions and actually can not use the editor. So the field needs to be text format, but for some users the editor may not be used. So we had a text format that had no editor active (what was possible in CKEditor 4, but now with the upgrade to Drupal 10, it gave issues)

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Thanks for the fast clarification!

    So the field needs to be text format, but for some users the editor may not be used. So we had a text format that had no editor active (what was possible in CKEditor 4, but now with the upgrade to Drupal 10, it gave issues)

    Even with no buttons, you'll still be able to create <p> and <br> in CKEditor 4/5 — without those tags, it cannot function.

    What you're describing indeed sounds like a use case for having NO text editor for that one text format. What problem did you run into when you tried doing that? 🤔

  • 🇧🇪Belgium Tim Lammar

    I don't remember exactly what errors occurred, but it had to do with the fact that in the code there are array methods used on toolbar items. These are in this case non existing and so causing php errors (something like expecting array, got NULL).
    The patch I provided in the previous ticket fixed the ones I encountered, but it's possible other places need to be fixed as well (ref: https://www.drupal.org/project/drupal/issues/3372452#comment-15136932 🐛 When a textformat has no text-editor configured ckeditor crashes Closed: duplicate )

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    I don't see how any toolbar item method would be getting invoked when no text editor is configured? 🤔

  • 🇧🇪Belgium Tim Lammar

    Exactly, but apparently it did 🤷‍♂️

Production build 0.69.0 2024