Deprecate core/modules/editor/js/editor.admin.js JS APIs in Drupal 10, for removal in Drupal 11

Created on 13 September 2015, almost 9 years ago
Updated 29 March 2024, 3 months ago

Problem/Motivation

core/modules/editor/js/editor.admin.js provides the following public JS APIs:

  1. Drupal.editorConfiguration
  2. Drupal.EditorFeatureHTMLRule
  3. Drupal.EditorFeature
  4. Drupal.FilterStatus
  5. Drupal.FilterHTMLRule
  6. Drupal.filterConfiguration
  7. Drupal.behaviors.initializeFilterConfiguration

Plus the things integrating with the above:

  1. Drupal.filterConfiguration.liveSettingParsers.filter_html.getRules()
  2. Drupal.behaviors.filterFilterHtmlUpdating
  3. Drupal.theme.filterFilterHTMLUpdateMessage

Crucially, none of this has any test coverage, because it predates FunctionalJavascript testing infrastructure.

Its docs say:

Provides a JavaScript API to broadcast text editor configuration changes.

Filter implementations may listen to the drupalEditorFeatureAdded,
drupalEditorFeatureRemoved, and drupalEditorFeatureRemoved events on document
to automatically adjust their settings based on the editor configuration.

Mea culpa

I wrote this, in #1894644: Unidirectional editor configuration -> filter settings syncing , over 9 years ago. It was how we made the UX for configuring CKEditor 4 somewhat decent: whenever you changed the CKEditor 4 toolbar (added buttons) or changed plugin settings (e.g. configured more styles for StylesCombo), it'd automatically update the filter_html filter configuration, to keep it in sync.

I already knew it was not great. It was a necessary evil. The follow-up work to make it decentnever happened (that was the original purpose of this issue, but it was recoped in #17).

The reason it's all in JS is simply because for CKEditor 4, it is impossible to know which HTML tags, attributes and attribute values a particular CKEditor capability needs (requires) or (optionally) supports. So … for CKEditor 4, we had a hidden CKEditor 4 instance right in the configuration UI, to query the capabilities "live". That's how we were able to keep filter_html in sync. Imperfectly (there are many bug reports around this, for example #2649546: [upstream] Alignment/justify buttons not appearing for CKEditor,

not being allowed automatically → ), but … better than nothing.

With CKEditor 5, we do know on the server side which HTML tags/attributes/attribute values are supported. This was critical to be able to have an upgrade path at all.

Which means all that infrastructure is unused in Drupal core.

That leaves one key question: does contrib use it at all? Let's find out:

Proposed resolution

Deprecate in 10.3.x, for removal in Drupal 11.

Remaining tasks

None.

User interface changes

None.

API changes

Deprecated everything in editor.admin.js: https://www.drupal.org/node/3422372

Data model changes

None.

📌 Task
Status

Fixed

Version

10.3

Component
Editor 

Last updated about 5 hours ago

Created by

🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

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

    Affects the content, performance, or handling of Javascript.

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.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Drupal 11 is getting close, so … let's finally get this done 🙈

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

    CR created: https://www.drupal.org/node/3422372

    Followed the guidelines in https://www.drupal.org/node/3082634 to deprecate JS APIs.

  • Pipeline finished with Failed
    4 months ago
    Total: 483s
    #98648
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Ran the javascript tests 3 times and they still fail so believe they are legit to the change.

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

    @smustgrave Yes, they still fail because core is still calling these APIs. And it has to, to avoid breaking BC. Which is what @lauriii indicated in his review on the MR.

    it could be tricky since I'm not sure there's a good way for us to retrieve the currently registered event listeners.

    Indeed. There is no way AFAICT.

    But there is one thing we can do, which I'd like to get @lauriii's thoughts on:

    1. editor.admin.js is loaded automatically for FilterFormatEditForm thanks to editor_form_filter_format_form_alter() doing
          '#attached' => [
            'library' => [
              'editor/drupal.editor.admin',
            ],
          ],
      
    2. but it's already the responsibility of each text editor that uses these APIs to depend on the editor/drupal.editor.admin asset library (otherwise it's possible it be loaded too late!) — the CKEditor 4 module does that too for example: https://git.drupalcode.org/project/ckeditor/-/blob/1.0.1/ckeditor.librar...
    3. therefore the solution is fairly simple: remove the auto-loading in #1, and instead rely on asset library dependencies, which it should've been doing all along

    (AFAICT the reason the auto-loading was still present: #1894644: Unidirectional editor configuration -> filter settings syncing introduced that asset library and predates strong use of dependencies, which happened a year later, in #1996238: Replace hook_library_info() by *.libraries.yml file .)

    Implemented that.

  • Pipeline finished with Failed
    4 months ago
    Total: 647s
    #99565
  • Status changed to Needs work 4 months ago
  • 🇫🇮Finland lauriii Finland

    Looks like core/modules/filter/filter.filter_html.admin.js has dependency on it, but it's not declaring it's dependencies correctly... 😅

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    That's because I should've deleted that too 😅

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • Status changed to Needs review 4 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺
  • Pipeline finished with Failed
    4 months ago
    Total: 512s
    #112044
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States smustgrave

    Seems to have a failing Filter javascript test.

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

    Ah, the sole failing test was one added (in #2556069: JS error with elements in "allowed HTML tags" that can't be direct descendants of a div ) for the functionality this is deprecating and no longer executing by default. It was to avoid this functionality regressing to the same bug again, but since this JS functionality is A) deprecated, B) has not been touched in years and won't be, there is no more need for this regression test 👍

  • Pipeline finished with Success
    4 months ago
    Total: 481s
    #114431
  • Status changed to RTBC 4 months ago
  • 🇺🇸United States smustgrave

    I don't know why but I chuckled reading "They were buggy ever since they were introduced in Drupal 8.0". Tests are showing green and deprecation links appear correct

    LGTM!

  • Status changed to Needs review 4 months ago
  • 🇬🇧United Kingdom catch

    already knew it was not great. It was a necessary evil. The follow-up work to make it decent (#2567801: Deprecate core/modules/editor/js/editor.admin.js JS APIs in Drupal 10, for removal in Drupal 11) never happened.

    This links back to here instead of linking to the issue. Not really a commit blocker but nice not to have circles.

    Text Filters reacting to Text Editors
    drupalEditorFeatureAdded → 1 result: linkit
    drupalEditorFeatureRemoved → 1 result: linkit
    drupalEditorFeatureModified → 0 results
    Conclusion: only one.

    Is this in linkit's CKEditor 4 integration? I checked and it's in the latest branch. If it's only for ckeditor4 integration then I think we just need a follow-up since maybe linkit can drop ckeditor4 support at this point rather than trying to update for this, if they're somehow relying on this for ckeditor5, then I thnk we would have to deprecate for removal in Drupal 12 at this point.

  • Status changed to RTBC 3 months ago
  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    #32: see #17 — I repurposed this issue 😅 Clarified that 👍

    Is this in linkit's CKEditor 4 integration? I checked and it's in the latest branch. If it's only for ckeditor4 integration then I think we just need a follow-up since maybe linkit can drop ckeditor4 support at this point rather than trying to update for this, if they're somehow relying on this for ckeditor5, then I thnk we would have to deprecate for removal in Drupal 12 at this point.

    You're >right. Yes, it's only for CKEditor 4. It can only be for CKEditor 4, because CKEditor 5 is not using any of the JS APIs that are being removed here.

    Note that LinkIt 6 supports both CKEditor 4 and 5 at our request: because it makes switching from 4 to 5 a lot less painful (both Editor plugins must be available simultaneously to be able to switch without shenanigans). I don't think a follow-up is necessary; this will just mean that the automatic updating of the filter_html format will stop working if you're setting up a NEW text format+editor to use CKEditor 4. But we're only deprecating it here (in Drupal 10.3), not removing it yet. You won't be able to have CKEditor 4 on Drupal 11 at all, so it getting removed then won't break anything 👍

    • catch committed 3eab4038 on 10.3.x
      Issue #2567801 by Wim Leers, lauriii: Deprecate core/modules/editor/js/...
    • catch committed a3930399 on 11.x
      Issue #2567801 by Wim Leers, lauriii: Deprecate core/modules/editor/js/...
  • Status changed to Fixed 3 months ago
  • 🇬🇧United Kingdom catch

    Thanks for confirming. linkit presumably will need to remove its own ckeditor4 support but that should probably happen in a branch that drops support for Drupal 10, so a bit further ahead than us doing so in Drupal 11.

    Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • 🇳🇱Netherlands Spokje

    Am a bit confused, but shouldn't the 11.x commit remove the core/modules/editor/js/editor.admin.js JS APIs?
    Or is this happening in a follow-up?
    Or am I just not reading this correctly?

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    Thanks! Really nice to see this code removed from Drupal core, it's probably the code I got in core that I was most ashamed of, so … relieved to see it gone 🌅 😄

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    CR published.

  • 🇬🇧United Kingdom catch

    Am a bit confused, but shouldn't the 11.x commit remove the core/modules/editor/js/editor.admin.js JS APIs?
    Or is this happening in a follow-up?
    Or am I just not reading this correctly?

    Since we've only just started removing deprecated code from 11.x, I've been assuming that new deprecations for 11.x removal will get caught by 'remove deprecated code in x' module issues or a final sweep before beta. It would be fine to do 11.x removal and 10.3.x deprecation MRs on one issue, but also there aren't many things we're deprecated for 11.x removal any more, and don't want to encourage people to do separate removal MRs for issues where we end up deprecated for removal in 12.x after all.

  • 🇧🇪Belgium Wim Leers Ghent 🇧🇪🇪🇺

    I've been assuming that new deprecations for 11.x removal will get caught by 'remove deprecated code in x' module issues or a final sweep before beta.

    Same!

    Especially for this one, where removal will be trivial 👍 (Delete a few lines in editor.libraries.yml, delete two *.js files, done!)

  • 🇳🇱Netherlands Spokje

    Since we've only just started removing deprecated code from 11.x, I've been assuming that new deprecations for 11.x removal will get caught by 'remove deprecated code in x' module issues or a final sweep before beta.

    Fine by me, although I think this is optimistic and at some point (maybe not in 10.3.x, but still, at some point) we will discover a big BC-issue at the last minute when doing such a final scan.

    Then again, there's always a fine balance between too many and too few rules and extra work for deprecations, so let's run with this :)

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

Production build 0.69.0 2024