From d49617248022c42f8a377b09740cd540b655b048 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Fri, 6 Jan 2023 10:06:41 +0000
Subject: [PATCH] Issue #3306597 by Wim Leers, Anchal_gupta, _utsavsharma,
 smustgrave: Improve usability of the "Enable image uploads" checkbox

---
 .../modules/ckeditor5/ckeditor5.libraries.yml |  5 ++++
 .../ckeditor5/js/ckeditor5.image.admin.js     | 30 +++++++++++++++++++
 core/modules/editor/editor.admin.inc          |  1 +
 3 files changed, 36 insertions(+)
 create mode 100644 core/modules/ckeditor5/js/ckeditor5.image.admin.js

diff --git a/core/modules/ckeditor5/ckeditor5.libraries.yml b/core/modules/ckeditor5/ckeditor5.libraries.yml
index a42b9434950c..5acd34d88bac 100644
--- a/core/modules/ckeditor5/ckeditor5.libraries.yml
+++ b/core/modules/ckeditor5/ckeditor5.libraries.yml
@@ -208,3 +208,8 @@ internal.admin.image:
   css:
     theme:
       css/image.admin.css: { }
+  js:
+    js/ckeditor5.image.admin.js: { }
+  dependencies:
+    - core/jquery
+    - core/drupal
diff --git a/core/modules/ckeditor5/js/ckeditor5.image.admin.js b/core/modules/ckeditor5/js/ckeditor5.image.admin.js
new file mode 100644
index 000000000000..5d9d9f9a1633
--- /dev/null
+++ b/core/modules/ckeditor5/js/ckeditor5.image.admin.js
@@ -0,0 +1,30 @@
+/**
+ * @file
+ * CKEditor 5 Image admin behavior.
+ */
+
+(function ($, Drupal) {
+  /**
+   * Provides the summary for the "image" plugin settings vertical tab.
+   *
+   * @type {Drupal~behavior}
+   *
+   * @prop {Drupal~behaviorAttach} attach
+   *   Attaches summary behavior to the plugin settings vertical tab.
+   */
+  Drupal.behaviors.ckeditor5ImageSettingsSummary = {
+    attach() {
+      $('[data-ckeditor5-plugin-id="ckeditor5_image"]').drupalSetSummary(
+        (context) => {
+          const uploadsEnabled = document.querySelector(
+            '[data-drupal-selector="edit-editor-settings-plugins-ckeditor5-image-status"]',
+          ).checked;
+          if (uploadsEnabled) {
+            return Drupal.t('Images can only be uploaded.');
+          }
+          return Drupal.t('Images can only be added by URL.');
+        },
+      );
+    },
+  };
+})(jQuery, Drupal);
diff --git a/core/modules/editor/editor.admin.inc b/core/modules/editor/editor.admin.inc
index 9e2cdc6114ac..6a474689d439 100644
--- a/core/modules/editor/editor.admin.inc
+++ b/core/modules/editor/editor.admin.inc
@@ -43,6 +43,7 @@ function editor_image_upload_settings_form(Editor $editor) {
     '#attributes' => [
       'data-editor-image-upload' => 'status',
     ],
+    '#description' => t('When enabled, images can only be uploaded. When disabled, images can only be added by URL.'),
   ];
   $show_if_image_uploads_enabled = [
     'visible' => [
-- 
GitLab