From acb4b8556def8e8f87333000e1fa8e71de2a9b31 Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Tue, 24 Nov 2020 12:01:40 +1000
Subject: [PATCH] Issue #3136406 by Spokje, codersukanta, IJsbrandy,
 atul4drupal, MahtabAlam, BalajiDS: Argument 1 passed to
 Drupal\Core\Form\SubformState::createForSubform() must be of the type array,
 null given

---
 core/modules/editor/editor.module               |  4 +++-
 .../tests/src/Functional/EditorAdminTest.php    | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module
index 4ccea91890da..0fb4267e776a 100644
--- a/core/modules/editor/editor.module
+++ b/core/modules/editor/editor.module
@@ -247,7 +247,9 @@ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_
     $original_editor->delete();
   }
 
-  if ($editor_plugin = $form_state->get('editor_plugin')) {
+  $editor_set = $form_state->getValue(['editor', 'editor']) !== "";
+  $subform_array_exists = (!empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform']));
+  if (($editor_plugin = $form_state->get('editor_plugin')) && $editor_set && $subform_array_exists) {
     $subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state);
     $editor_plugin->submitConfigurationForm($form['editor']['settings']['subform'], $subform_state);
   }
diff --git a/core/modules/editor/tests/src/Functional/EditorAdminTest.php b/core/modules/editor/tests/src/Functional/EditorAdminTest.php
index 097f8fab2010..5ddf50f36143 100644
--- a/core/modules/editor/tests/src/Functional/EditorAdminTest.php
+++ b/core/modules/editor/tests/src/Functional/EditorAdminTest.php
@@ -156,6 +156,23 @@ public function testDisableFormatWithEditor() {
     $this->assertRaw($text);
   }
 
+  /**
+   * Tests switching text editor to none does not throw a TypeError.
+   */
+  public function testSwitchEditorToNone() {
+    $this->enableUnicornEditor();
+    $this->drupalLogin($this->adminUser);
+    $this->drupalGet('admin/config/content/formats/manage/filtered_html');
+    $edit = $this->selectUnicornEditor();
+
+    // Switch editor to 'None'.
+    $edit = [
+      'editor[editor]' => '',
+    ];
+    $this->submitForm($edit, 'Configure');
+    $this->submitForm($edit, 'Save configuration');
+  }
+
   /**
    * Adds an editor to a new format using the UI.
    *
-- 
GitLab