Problem/Motivation

Currently, the plugin definition defines a drupal.conditions.filter property and a drupal.conditions.toolbarItem property. The value of each can be a single string. But what if a contrib plugin can only be enabled if 2 different filters are enabled or if 2 different toolbar items are added?

Steps to reproduce

Proposed resolution

Point to the following handbook page in the ckeditor5.api.php file CKEditor 5 API overview

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

effulgentsia created an issue. See original summary.

wim leers’s picture

High-level thoughts

Great point! Those are edge cases we had not yet thought about.

Note that this current limited set of possible conditions was intentional. drupal.conditions is intentionally hardcoded to support only the most common scenarios right now; see #3216244: Remove CKEditor5PluginContextualInterface and CKEditor5PluginContextualValidationInterface in favor of annotation for the history.

The idea is that it's better to make the common kinds failproof, avoid duplicate-but-subtly-different-and-broken logic (which is a problem we actually had). We can continue adding more kinds of conditions in the future.

Challenge in the proposal

When you require >1 filter or toolbar item that implies AND. But what if for some case it's OR?

Implementation notes

If the challenge is not a concern, and we think we should move forward with AND by simply accepting arrays of strings instead of a single string for both kinds of conditions, then I'm fine with that. What do we need to do for that?

  1. We'd need to expand \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConditionsMetConstraintValidator::validate(), which has explicit test coverage since #3231220: Follow-up for #3216244: AdminUi::validateConditions() does not work, convert to validation constraint.
  2. We should also add this to \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateDrupalAspects(), much like we already did recently in #3231327: Plugin definition DX: validate ckeditor5.drupal.elements items and #3228505: Plugin definition DX: automatically check for plugin definitions whether their ::getDefaultSettings() matches the config schema
effulgentsia’s picture

If we think it's truly an edge case, we could punt on it, and then in the future, add new properties, like filters and toolbarItems, so people can use the singular form for the common case and the plural form for the edge cases. We could then handle the OR case with yet a different name, like filtersOneOf and toolbarItemsOneOf.

Alternatively, we could overload the existing filter and toolbarItem properties to be either strings or arrays.

Either of the above approaches could be done in a BC way, so if we're happy with that, I'm fine with punting for now. But if we'd prefer an approach that would involve a BC break relative to what's in there now, then let's break that prior to merging this into core.

effulgentsia’s picture

Also, if we punt on this, let's add a @todo linking to this issue in ckeditor5.api.php where these properties are documented.

wim leers’s picture

add new properties, like […]

Exactly!

We could then handle the OR case with yet a different name

Indeed :)

Alternatively, we could overload the existing filter and toolbarItem properties to be either strings or arrays.

That would be more complicated; we can't really express such optional different data shapes in config schema…

Also, if we punt on this, let's add a @todo linking to this issue in ckeditor5.api.php where these properties are documented.

+1

wim leers’s picture

Status: Postponed (maintainer needs more info) » Needs review

My experience

As another data point: https://www.drupal.org/project/linkit (on whose CKE5 support we already worked: #3232190: CKEditor 5 readiness) has an optional filter, \Drupal\linkit\Plugin\Filter\LinkitFilter.

From everything I've seen in the filter system (which is a lot because I also worked a lot on D7 → D9 migrations) and CKEditor 4 plugins (which I've seen a good share of), I think it is very rare for text editor functionality to depend on multiple filters.

My opinion

That's why I personally would prefer the first option suggested in #3: add more kinds of conditions in the future (filters, filtersOneOf, etc.), and add a @todo linking to this issue from ckeditor5.api.php. Does that mean we should keep this issue open as a meta issue then? Or do we add that @todo in this issue and close this, just point to this as the conversation where this happened? What do you propose?

wim leers’s picture

#3248188: Plugin definition DX: validate drupal.conditions will help prevent WTFs, and will also help identify the need for more conditions.

EDIT: that will do what I wrote in #2:

  1. We should also add this to \Drupal\ckeditor5\Plugin\CKEditor5PluginDefinition::validateDrupalAspects(), much like we already did recently in #3231327: Plugin definition DX: validate ckeditor5.drupal.elements items and #3228505: Plugin definition DX: automatically check for plugin definitions whether their ::getDefaultSettings() matches the config schema
wim leers’s picture

Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module
wim leers’s picture

Assigned: Unassigned » effulgentsia

Back to @effulgentsia for review.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

The one place where the need for >1 filter condition came up so far was #3261061: Allow filter condition to depend on multiple filters, and that actually did end up not needing it. Better yet: it didn't only not need it, there was a better alternative solution: #3261061-3: Allow filter condition to depend on multiple filters.

P.S.: #3248188: Plugin definition DX: validate drupal.conditions landed in the meantime!

effulgentsia’s picture

Title: Consider whether a plugin might need >1 filter condition or >1 toolbarItem condition » Point CKE5 plugin authors to this issue if they need more complex conditions than the current API supports
Assigned: effulgentsia » Unassigned
Category: Feature request » Task
StatusFileSize
new1.26 KB

How's this?

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

That totally works :)

lauriii’s picture

Is the plan to keep this issue open after committing so that people can report their use cases? Just wondering what are we expecting to happen when folks land on this issue.

effulgentsia’s picture

I think that after commit, we should close the issue, but maybe update the issue summary letting people know to reopen it if/when the need arises.

wim leers’s picture

+1

lauriii’s picture

Wouldn’t that prevent non-privileged users from acting on this since they wouldn’t be able to re-open the issue?

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

Moving to Needs review to get #17 addressed.

wim leers’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
StatusFileSize
new11.45 KB

I propose to ask them to create a child issue of this issue. Updated issue summary.

xjm’s picture

Status: Reviewed & tested by the community » Needs work

Referencing closed issues in the API docs is generally against coding standards. Also, children of a closed issue are not really discoverable.

Could we instead add a section to the CKE5 developer handbook page with instructions, link to the relevant header (with fragment), and tell them what to do in the handbook section? Then, convert this to a plan issue and leave it Active. That way we can change what the handbook section says after CKEditor 5 is stable and in Standard, to instead tell them to do the standard thing ("Major" and "Contributed project blocker" issue in the core queue), since I assume that we are not going to be checking back to this issue after it's closed for eternity.

wim leers’s picture

Assigned: Unassigned » effulgentsia

Could we instead add a section to the CKE5 developer handbook page with instructions, link to the relevant header (with fragment)

This is impossible to guarantee link reliability for, especially with the fragment. The fragment can be broken by anybody who can modify docs, and drupal.org has been known to break fragments in the past with its own infrastructure changes.

Then, convert this to a plan issue and leave it Active.

… but that would mean that this issue remains open even after the commit?

So, actually … why are we doing all these weird things? For everything else in Drupal core we also expect people to just create new feature requests and use git blame to figure out what the appropriate issues are? So why not do the same here?

xjm’s picture

So, actually … why are we doing all these weird things? For everything else in Drupal core we also expect people to just create new feature requests and use git blame to figure out what the appropriate issues are? So why not do the same here?

Yep, agreed with this in general and for this issue. However, I still think putting in a link to handbook docs is a good idea. Yes, link fragments get broken, but if we hardcode an ID it's less likely, and URL redirects still exist forever so they will always end up on the right page. It is a good idea to have a developer CTA.

wim leers’s picture

Status: Needs work » Needs review
StatusFileSize
new898 bytes
new1.31 KB

Done. That was a whole ordeal.

I had to create https://www.drupal.org/docs/drupal-apis/ckeditor-5-api to be the sibling of https://www.drupal.org/docs/drupal-apis/ckeditor-api. But I can't get it to be listed in https://www.drupal.org/docs/drupal-apis 🤷‍♂️ Even though everything looks exactly the same.

Fortunately, I was able to create https://www.drupal.org/docs/drupal-apis/ckeditor-5-api/overview (as the successor of https://www.drupal.org/docs/8/api/ckeditor-api/overview) just fine.

There, I added https://www.drupal.org/docs/drupal-apis/ckeditor-5-api/overview#conditions to be able to do what @xjm requested here.

wim leers’s picture

Title: Point CKE5 plugin authors to this issue if they need more complex conditions than the current API supports » CKEditor 5 plugins needing more complex conditions: point to handbook page

Update title to match the new direction.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

I think the IS is also out of date.

nod_’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
nod_’s picture

  • catch committed 523894d on 10.0.x
    Issue #3246246 by Wim Leers, effulgentsia, lauriii, xjm, nod_: CKEditor...
  • catch committed e67c685 on 10.1.x
    Issue #3246246 by Wim Leers, effulgentsia, lauriii, xjm, nod_: CKEditor...
  • catch committed f0944d2 on 9.5.x
    Issue #3246246 by Wim Leers, effulgentsia, lauriii, xjm, nod_: CKEditor...
catch’s picture

Title: CKEditor 5 plugins needing more complex conditions: point to handbook page » CKEditor 5 plugins needing more complex conditions
Assigned: effulgentsia » Unassigned
Category: Task » Plan
Status: Reviewed & tested by the community » Fixed

I'm not sure why we didn't just leave this open as a feature request or similar, but committed/pushed to 10.1.x and cherry-picked back through to 9.4.x.

  • catch committed 0c53214 on 9.4.x
    Issue #3246246 by Wim Leers, effulgentsia, lauriii, xjm, nod_: CKEditor...

Status: Fixed » Closed (fixed)

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