Problem/Motivation

The bug that #3248177: Language toolbar item cannot be removed from the toolbar uncovered and fixed revealed that some textPartLanguage-specific validation logic should be generalized.

Right now it's possible to have for example heading plugin configuration without having the heading plugin enabled!

Steps to reproduce

Enable Heading plugin by activating its button. Configure it. Now remove the Heading button. No error, but the exported configuration entity still contains the configuration!

Proposed resolution

Generalize textPartLanguage's validation: always trigger this validation error for any plugins that have both toolbar items ($definition->hasToolbarItems() === TRUE) and configuration ($definition->isConfigurable() === TRUE).

Remaining tasks

  1. Remove CKEditor5ToolbarItemDependencyConstraint from ckeditor5.plugin.ckeditor5_language in ckeditor5.schema.yml.
  2. Move CKEditor5ToolbarItemDependencyConstraint to editor.settings.ckeditor5's plugins child key.
  3. Update the logic in ToolbarItemDependencyConstraintValidator to iterate over each of the received plugin keys, get the plugin definition, check if it has buttons (otherwise continue), then run the current validation logic.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

CommentFileSizeAuthor
#6 3259795-6-alt.patch6.33 KBwim leers

Issue fork drupal-3259795

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

Wim Leers created an issue. See original summary.

marcvangend made their first commit to this issue’s fork.

marcvangend’s picture

I've been looking at the proposed solution and the existing code. Please correct me if I'm wrong, but I think I understand the following.

Basically, this generalized constraint validator will be a lot like EnabledConfigurablePluginsConstraintValidator, albeit the other way around. While EnabledConfigurablePluginsConstraintValidator checks if each enabled configurable plugin ("toolbar item") has corresponding plugin settings, we now want to check if each set of plugin settings corresponds to an enabled configurable plugin. Right?

If the above is correct, wouldn't it make sense to scrap CKEditor5ToolbarItemDependencyConstraint completely and enhance EnabledConfigurablePluginsConstraintValidator to perform the validation in both directions?

marcvangend’s picture

Status: Active » Needs review

Just pushed a first attempt at a more generalized constraint validator for plugin settings. In the end I didn't exactly follow the proposed resolution from the issue summary.

I chose not to merge it into EnabledConfigurablePluginsConstraintValidator, as I briefly considered in #3, because it's probably better to have two separate, more simple constraints.

The result is a constraint called ConfigurablePluginSettingsConstraint. It does for each item in the plugin settings what ToolbarItemDependencyConstraint did for only the specified one: check if the corresponding plugin is enabled on the toolbar. The code to make this work was mostly inspired by EnabledConfigurablePluginsConstraintValidator.

Note that this is just a validator - removing configurable plugins from the toolbar now throws errors at you. If I understand correctly, this is not a new problem, we're just exposing it.

Todo's:

  1. Review and discuss if this the correct approach
  2. Remove ToolbarItemDependencyConstraint|ToolbarItemDependencyConstraintValidator
  3. Alter the test in \Drupal\Tests\ckeditor5\Kernel\ValidatorsTest to cover the new constraint
  4. Follow up, or even precede this with: Make sure that removing a configurable plugin from the toolbar immediately removes its settings
wim leers’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update
StatusFileSize
new6.33 KB

Steps to reproduce

Enable Heading plugin by activating its button. Configure it. Now remove the Heading button. No error, but the exported configuration entity still contains the configuration!

These steps to reproduce no longer work since #3248177: Language toolbar item cannot be removed from the toolbar.

The only way to create such nonsensical configuration (i.e. containing plugin settings for a plugin that is not enabled) is by manually modifying configuration.

That means this is now hardening for a pretty remote edge case. So I think we could change this MR to do this instead: remove CKEditor5ToolbarItemDependencyConstraint altogether. Of course, we could continue to do what this MR does to protect against manual config changes. That'd be the safer choice. I'm personally still in favor of doing this MR, I just wanted to lay the options on the table.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.