From 3eab403895fb161aca1eddd5168aa4ebdd7afa6c Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 15 Mar 2024 09:21:44 +0000
Subject: [PATCH] Issue #2567801 by Wim Leers, lauriii: Deprecate
 core/modules/editor/js/editor.admin.js JS APIs in Drupal 10, for removal in
 Drupal 11

(cherry picked from commit a3930399c257d6268550d8568f9cd35b2d33dac3)
---
 core/modules/editor/editor.libraries.yml      |  1 +
 core/modules/editor/editor.module             |  5 --
 core/modules/editor/js/editor.admin.js        | 62 +++++++++++++++++++
 .../filter/filter.filter_html.admin.js        | 13 ++++
 core/modules/filter/filter.libraries.yml      |  1 +
 .../filter/src/Plugin/Filter/FilterHtml.php   |  5 --
 .../FunctionalJavascript/FilterHtmlTest.php   | 54 ----------------
 7 files changed, 77 insertions(+), 64 deletions(-)
 delete mode 100644 core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php

diff --git a/core/modules/editor/editor.libraries.yml b/core/modules/editor/editor.libraries.yml
index bd46f6e86491..7fe5bf56219e 100644
--- a/core/modules/editor/editor.libraries.yml
+++ b/core/modules/editor/editor.libraries.yml
@@ -6,6 +6,7 @@ drupal.editor.admin:
     - core/jquery
     - core/once
     - core/drupal
+  deprecated: The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. See https://www.drupal.org/node/3422372
 
 drupal.editor:
   version: VERSION
diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module
index 6925eea7b140..d8ec411e9aeb 100644
--- a/core/modules/editor/editor.module
+++ b/core/modules/editor/editor.module
@@ -149,11 +149,6 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s
     '#weight' => -8,
     '#type' => 'container',
     '#id' => 'editor-settings-wrapper',
-    '#attached' => [
-      'library' => [
-        'editor/drupal.editor.admin',
-      ],
-    ],
   ];
 
   // Add editor-specific validation and submit handlers.
diff --git a/core/modules/editor/js/editor.admin.js b/core/modules/editor/js/editor.admin.js
index 6f8aa9dce28d..b4fa10e3d67a 100644
--- a/core/modules/editor/js/editor.admin.js
+++ b/core/modules/editor/js/editor.admin.js
@@ -27,6 +27,10 @@
      * @fires event:drupalEditorFeatureAdded
      */
     addedFeature(feature) {
+      Drupal.deprecationError({
+        message:
+          'Drupal.editorConfiguration.addedFeature is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
       $(document).trigger('drupalEditorFeatureAdded', feature);
     },
 
@@ -43,6 +47,10 @@
      * @fires event:drupalEditorFeatureRemoved
      */
     removedFeature(feature) {
+      Drupal.deprecationError({
+        message:
+          'Drupal.editorConfiguration.removedFeature is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
       $(document).trigger('drupalEditorFeatureRemoved', feature);
     },
 
@@ -62,6 +70,10 @@
      * @fires event:drupalEditorFeatureModified
      */
     modifiedFeature(feature) {
+      Drupal.deprecationError({
+        message:
+          'Drupal.editorConfiguration.modifiedFeature is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
       $(document).trigger('drupalEditorFeatureModified', feature);
     },
 
@@ -657,6 +669,11 @@
         return true;
       }
 
+      Drupal.deprecationError({
+        message:
+          'Drupal.editorConfiguration.featureIsAllowedByFilters is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
+
       // If any filter's current status forbids the editor feature, return
       // false.
       Drupal.filterConfiguration.update();
@@ -702,6 +719,11 @@
    * @see Drupal.EditorFeature
    */
   Drupal.EditorFeatureHTMLRule = function () {
+    Drupal.deprecationError({
+      message:
+        'Drupal.EditorFeatureHTMLRule is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     /**
      *
      * @type {Object}
@@ -768,6 +790,11 @@
    * @see Drupal.EditorFeatureHTMLRule
    */
   Drupal.EditorFeature = function (name) {
+    Drupal.deprecationError({
+      message:
+        'Drupal.EditorFeature is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     this.name = name;
     this.rules = [];
   };
@@ -779,6 +806,11 @@
    *   A text editor feature HTML rule.
    */
   Drupal.EditorFeature.prototype.addHTMLRule = function (rule) {
+    Drupal.deprecationError({
+      message:
+        'Drupal.EditorFeature.prototype.addHTMLRule is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     this.rules.push(rule);
   };
 
@@ -806,6 +838,11 @@
    * @see Drupal.FilterHTMLRule
    */
   Drupal.FilterStatus = function (name) {
+    Drupal.deprecationError({
+      message:
+        'Drupal.FilterStatus is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     /**
      *
      * @type {string}
@@ -832,6 +869,11 @@
    *   A text filter HTML rule.
    */
   Drupal.FilterStatus.prototype.addHTMLRule = function (rule) {
+    Drupal.deprecationError({
+      message:
+        'Drupal.FilterStatus.prototype.addHTMLRule is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     this.rules.push(rule);
   };
 
@@ -911,6 +953,11 @@
    * @see Drupal.FilterStatus
    */
   Drupal.FilterHTMLRule = function () {
+    Drupal.deprecationError({
+      message:
+        'Drupal.FilterHTMLRule is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     // Allow or forbid tags.
     this.tags = [];
     this.allow = null;
@@ -926,6 +973,11 @@
   };
 
   Drupal.FilterHTMLRule.prototype.clone = function () {
+    Drupal.deprecationError({
+      message:
+        'Drupal.FilterHTMLRule.prototype.clone is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
+
     const clone = new Drupal.FilterHTMLRule();
     clone.tags = this.tags.slice(0);
     clone.allow = this.allow;
@@ -984,6 +1036,11 @@
      * up-to-date.
      */
     update() {
+      Drupal.deprecationError({
+        message:
+          'Drupal.filterConfiguration.update is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
+
       Object.keys(Drupal.filterConfiguration.statuses || {}).forEach(
         (filterID) => {
           // Update status.
@@ -1013,6 +1070,11 @@
    */
   Drupal.behaviors.initializeFilterConfiguration = {
     attach(context, settings) {
+      Drupal.deprecationError({
+        message:
+          'Drupal.behaviors.initializeFilterConfiguration is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
+
       once(
         'filter-editor-status',
         '#filters-status-wrapper input.form-checkbox',
diff --git a/core/modules/filter/filter.filter_html.admin.js b/core/modules/filter/filter.filter_html.admin.js
index c830879743ad..87eef5bb93c8 100644
--- a/core/modules/filter/filter.filter_html.admin.js
+++ b/core/modules/filter/filter.filter_html.admin.js
@@ -18,6 +18,10 @@
        *   An array of filter rules.
        */
       getRules() {
+        Drupal.deprecationError({
+          message:
+            'Drupal.filterConfiguration.liveSettingParsers.filter_html.getRules() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+        });
         const currentValue = document.querySelector(
           '#edit-filters-filter-html-settings-allowed-html',
         ).value;
@@ -82,6 +86,11 @@
     newFeatures: {},
 
     attach(context, settings) {
+      Drupal.deprecationError({
+        message:
+          'Drupal.behaviors.filterFilterHtmlUpdating is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+      });
+
       const that = this;
       once(
         'filter-filter_html-updating',
@@ -393,6 +402,10 @@
    *   The corresponding HTML.
    */
   Drupal.theme.filterFilterHTMLUpdateMessage = function (tags) {
+    Drupal.deprecationError({
+      message:
+        'Drupal.theme.filterFilterHTMLUpdateMessage() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. See https://www.drupal.org/node/3422372.',
+    });
     let html = '';
     const tagList =
       Drupal.behaviors.filterFilterHtmlUpdating._generateSetting(tags);
diff --git a/core/modules/filter/filter.libraries.yml b/core/modules/filter/filter.libraries.yml
index 108d6b92dc10..7dc9b0153681 100644
--- a/core/modules/filter/filter.libraries.yml
+++ b/core/modules/filter/filter.libraries.yml
@@ -15,6 +15,7 @@ drupal.filter.filter_html.admin:
   dependencies:
     - core/jquery
     - core/once
+  deprecated: The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. See https://www.drupal.org/node/3422372
 
 drupal.filter:
   version: VERSION
diff --git a/core/modules/filter/src/Plugin/Filter/FilterHtml.php b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
index 4bee00b5741c..f1a037ba07ae 100644
--- a/core/modules/filter/src/Plugin/Filter/FilterHtml.php
+++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
@@ -50,11 +50,6 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
       '#title' => $this->t('Allowed HTML tags'),
       '#default_value' => $this->settings['allowed_html'],
       '#description' => $this->t('A list of HTML tags that can be used. By default only the <em>lang</em> and <em>dir</em> attributes are allowed for all HTML tags. Each HTML tag may have attributes which are treated as allowed attribute names for that HTML tag. Each attribute may allow all values, or only allow specific values. Attribute names or values may be written as a prefix and wildcard like <em>jump-*</em>. JavaScript event attributes, JavaScript URLs, and CSS are always stripped.'),
-      '#attached' => [
-        'library' => [
-          'filter/drupal.filter.filter_html.admin',
-        ],
-      ],
     ];
     $form['filter_html_help'] = [
       '#type' => 'checkbox',
diff --git a/core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php b/core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php
deleted file mode 100644
index 15fa2c72cf2b..000000000000
--- a/core/modules/filter/tests/src/FunctionalJavascript/FilterHtmlTest.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Drupal\Tests\filter\FunctionalJavascript;
-
-use Drupal\filter\Entity\FilterFormat;
-use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
-
-/**
- * Tests the 'filter_html' plugin javascript functionality.
- *
- * @group filter
- */
-class FilterHtmlTest extends WebDriverTestBase {
-
-  /**
-   * {@inheritdoc}
-   */
-  protected static $modules = ['editor', 'filter'];
-
-  /**
-   * {@inheritdoc}
-   */
-  protected $defaultTheme = 'stark';
-
-  /**
-   * Tests restricting HTML to table tags.
-   */
-  public function testTableTags() {
-    FilterFormat::create([
-      'format' => 'some_html',
-      'name' => 'Some HTML',
-      'filters' => [
-        'filter_html' => [
-          'status' => 1,
-          'settings' => [
-            'allowed_html' => '<caption> <tbody> <thead> <tfoot> <th> <td> <tr>',
-          ],
-        ],
-      ],
-    ])->save();
-
-    $this->drupalLogin($this->drupalCreateUser(['administer filters']));
-    $this->drupalGet('admin/config/content/formats/manage/some_html');
-
-    $js_condition = "Drupal.behaviors.filterFilterHtmlUpdating._parseSetting(
-      jQuery('#edit-filters-filter-html-settings-allowed-html').val()
-    )['td'].tags.length >= 0";
-
-    $this->assertJsCondition($js_condition);
-  }
-
-}
-- 
GitLab