Fix <ol start> → native CKEditor 5 functionality and fix bug in SourceEditingRedundantTagsConstraintValidator that allowed it to slip by

Created on 25 October 2023, 7 months ago
Updated 28 November 2023, 6 months ago

Problem/Motivation

📌 Use CKEditor 5's native support (and also support ) Fixed should've introduced an update hook for replacing <ol start type> in the Basic HTML editor in Standard to just <ol type>.

But … it didn't.

Tests didn't fail. Because Source Editing didn't complain.

This means \Drupal\ckeditor5\Plugin\Validation\Constraint\SourceEditingRedundantTagsConstraintValidator is not working precisely enough.

Discovered this over at [upstream] Use CKEditor 5's native and UX Needs work .

Steps to reproduce

Proposed resolution

  1. Add explicit test coverage
  2. Tighten validator
  3. Fix Standard's default config
  4. Write update path

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

N/A

🐛 Bug report
Status

Fixed

Version

10.2

Component
CKEditor 5 

Last updated 1 day ago

Created by

🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

Live updates comments and jobs are added and updated live.
  • Usability

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

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

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

  • Issue created by @Wim Leers
  • Assigned to Wim Leers
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Tightening this validator should make \Drupal\Tests\standard\Functional\StandardTest fail.

    Which in turn should require us to write the missing update path hook.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    This blocks [upstream] Use CKEditor 5's native and UX Needs work .

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Turns out this is caused by:

            // If the entirety (so not just the tag but also the attributes, and not
            // just some of the attribute values, but all of them) of the HTML
            // elements being configured to be edited via the Source Editing plugin
            // is supported by a CKEditor 5 plugin, complain. But if some attribute
            // or some attribute value is still not yet supported, do not generate a
            // violation message.
            // If there is overlap, but some attribute/attribute value is still not
            // supported, exit this iteration without generating a violation
            // message. Essentially: when assessing a particular value
            // (for example `<foo bar baz>`), only CKEditor 5 plugins providing an
            // exact match (`<foo bar baz>`) or a superset (`<foo bar baz qux>`) can
            // trigger a violation, not subsets (`<foo bar>`).
            if ($is_attr_overlap && !$source_enabled_element->diff($overlap)->allowsNothing()) {
              continue;
            }
    

    This was introduced by #3260857: Expand SourceEditingRedundantTagsConstraintValidator to also check attributes and attribute values .

  • Merge request !5137Add explicit test coverage. → (Open) created by Wim Leers
  • last update 7 months ago
    Custom Commands Failed
  • last update 7 months ago
    540 pass, 1 fail
  • last update 7 months ago
    30,319 pass, 66 fail
  • last update 7 months ago
    30,362 pass, 4 fail
  • last update 7 months ago
    30,438 pass
  • last update 7 months ago
    Custom Commands Failed
  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • last update 7 months ago
    30,441 pass
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • 🇺🇸United States smustgrave

    Running the test-only feature

    But @wim leers left 1 question and 1 nitpicky.

    LEaving in review.

  • last update 7 months ago
    30,441 pass
  • Assigned to Wim Leers
  • Status changed to Needs work 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Just realized something: \Drupal\ckeditor5\Plugin\CKEditor4To5Upgrade\Core::computeCKEditor5PluginSubsetConfiguration()'s case 'ckeditor5_list': should also be updated.

  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Oops, #9 was meant to be posted on [upstream] Use CKEditor 5's native and UX Needs work 😅

  • Status changed to RTBC 7 months ago
  • 🇺🇸United States smustgrave

    I was actually confused for a second haha.

    Test-only feature failed as expected.

    Post_update ran without issue on a standard profile.

    So think this is good.

  • last update 7 months ago
    30,467 pass
  • last update 7 months ago
    30,484 pass
  • last update 7 months ago
    30,486 pass
  • Assigned to Wim Leers
  • Status changed to Needs work 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    📌 [upstream] Update CKEditor 5 to 40.0.0 Needs review landed, this needs a rebase & conflict resolution.

  • Status changed to Needs review 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Hoping @smustgrave can review this one more time — found a pretty big bug during rebasing 😅

  • Issue was unassigned.
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • 🇧🇪Belgium borisson_ Mechelen, 🇧🇪

    There is a failure in the tests, but it looks like that is unrelated and I'm not sure how to rerun tests with gitlab, this looks rtbc imho

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Retesting — Nightwatch & Functional JS have been a bit flakey this week…

  • Status changed to RTBC 7 months ago
  • 🇺🇸United States smustgrave

    Retesting — Nightwatch & Functional JS have been a bit flakey this week…

    Extremely flakey!

    Also agree this looks good!

  • last update 7 months ago
    30,513 pass
  • Status changed to Needs work 7 months ago
  • 🇫🇮Finland lauriii Finland

    I posted couple comments in the MR

  • Assigned to Wim Leers
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Thanks to @lauriii, a new edge case has been found: because SourceEditingRedundantTagsConstraintValidator was originally designed to handle tags, this code made sense:

        // An array of tags enabled by every plugin other than Source Editing.
        $enabled_plugin_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($other_enabled_plugins), $text_editor, FALSE));
        $disabled_plugin_elements = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($enableable_disabled_plugins), $text_editor, FALSE));
        $enabled_plugin_plain_tags = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($other_enabled_plugins), $text_editor, FALSE, TRUE));
        $disabled_plugin_plain_tags = new HTMLRestrictions($this->pluginManager->getProvidedElements(array_keys($enableable_disabled_plugins), $text_editor, FALSE, TRUE));
    

    However … in the case of plugins with optional additional attributes, the above will result for

          'settings' => [
            'toolbar' => [
              'items' => [
                'numberedList',
                'sourceEditing',
              ],
            ],
            'plugins' => [
              'ckeditor5_list' => [
                'properties' => [
                  'reversed' => FALSE,
                  'startIndex' => FALSE,
                ],
                'multiBlock' => TRUE,
              ],
              'ckeditor5_sourceEditing' => [
                'allowed_tags' => [
                  '<ol start type>',
                ],
              ],
            ],
    

    in concluding that for the enabled ckeditor5_list plugin, the following things can be generated: <ul> <ol> <li> … because of

                'properties' => [
                  'reversed' => FALSE,
                  'startIndex' => FALSE,
                ],
    

    IOW: what's missing here is what additional attributes could be generated by enabling optional settings! 🐣

  • Issue was unassigned.
  • Status changed to Needs review 7 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Fixing Umami's editor config nicely triggered a validation error in the corresponding filter_format config:

    Drupal\Tests\demo_umami\Functional\DemoUmamiProfileTest::testConfig
    Failed asserting that two arrays are identical.
    --- Expected
    +++ Actual
    @@ @@
    -Array &0 ()
    +Array &0 (
    +    0 => 'The CKEditor 5 "<em class="placeholder">Media</em>" plugin's "<em class="placeholder">Allow the user to override the default view mode</em>" setting should be in sync with the "<em class="placeholder">Embed media</em>" filter's "<em class="placeholder">View modes selectable in the &quot;Edit media&quot; dialog</em>" setting: when checked, two or more view modes must be allowed by the filter.'
    +)
    

    👍

    Fixed that too now — ready for review again, and WHAT A GREAT FIND from @lauriii 👏

  • Status changed to RTBC 7 months ago
  • 🇺🇸United States smustgrave

    Threads appear to be answered and pipeline showing green. No randoms this time!

  • last update 7 months ago
    30,519 pass
  • last update 7 months ago
    30,523 pass
  • 34:31
    33:23
    Running
  • last update 7 months ago
    30,563 pass
  • Status changed to Needs work 7 months ago
  • 🇬🇧United Kingdom catch

    Left a comment on the MR regarding the post update.

  • 🇺🇸United States xjm

    Reposting my question from Slack: Does the upgrade path work from both Drupal 9 and CKE4 as well as from CKE5/Drupal 10 content getting updated a second time? Moving the fix to presave would also help with that aspect, but it still needs its own consideration since the source data formats from the two versions would be different.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    #23: did that. 👍

    #24:

    Does the upgrade path work from both Drupal 9 and CKE4 as well as from CKE5/Drupal 10 content getting updated a second time?

    Yes.

  • Status changed to RTBC 6 months ago
  • 🇬🇧United Kingdom longwave UK

    This change involves an upgrade path but the update is small, self-contained, has no BC concerns that I can see, and fixes a major bug, therefore I think the impact outweighs the disruption and therefore this can be committed during the beta phase of 10.2.0. It's also nice that we found and fixed extra config validation violations here!

    Committed and pushed bcf5a9159e to 11.x and ec24a58c6d to 10.2.x. Thanks!

    • longwave committed ec24a58c on 10.2.x
      Issue #3396628 by Wim Leers, smustgrave, lauriii, xjm, catch: Fix...
  • Status changed to Fixed 6 months ago
    • longwave committed bcf5a915 on 11.x
      Issue #3396628 by Wim Leers, smustgrave, lauriii, xjm, catch: Fix...
  • 🇬🇧United Kingdom catch

    I think the rule is: for all config entities, always

    Yes, this is correct :) Anything that could be in the database but also potentially in config shipped with a module.

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

  • 🇺🇸United States joshuami Portland, OR

    joshuami changed the visibility of the branch 3396628-tighten-sourceeditingredundanttagsconstraintvalidator to hidden.

Production build 0.69.0 2024