Loading core/.phpstan-baseline.php +0 −6 Changes for core/.phpstan-baseline.php: 0 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -14125,12 +14125,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php', ]; $ignoreErrors[] = [ 'message' => '#^Function editor_form_filter_admin_form_ajax\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/editor/editor.module', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\editor\\\\Ajax\\\\EditorDialogSave\\:\\:render\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php +3 −1 Changes for core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -522,7 +522,7 @@ public function filterFormatEditFormSubmit(array $form, FormStateInterface $form /** * AJAX callback handler for filter_format_form(). * * Used instead of editor_form_filter_admin_form_ajax from the editor module. * Used instead of EditorHooks::editorFormFilterAdminFormAjax(). * * @param array $form * The form render array. Loading @@ -531,6 +531,8 @@ public function filterFormatEditFormSubmit(array $form, FormStateInterface $form * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. * * @see \Drupal\editor\Hook\EditorHooks::editorFormFilterAdminFormAjax() */ public function updateCkeditor5HtmlFilter(array $form, FormStateInterface $form_state): AjaxResponse { $response = new AjaxResponse(); Loading core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php +4 −2 Changes for core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use Drupal\editor\Attribute\Editor; use Drupal\editor\EditorInterface; use Drupal\editor\Entity\Editor as EditorEntity; use Drupal\editor\Hook\EditorHooks; use Drupal\editor\Plugin\EditorBase; use Drupal\filter\FilterFormatInterface; use Psr\Log\LoggerInterface; Loading Loading @@ -661,7 +662,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form // Special case: AJAX updates that do not submit the form (that cannot // result in configuration being saved). if (in_array('editor_form_filter_admin_format_editor_configure', $form_state->getSubmitHandlers(), TRUE)) { if (in_array(EditorHooks::class . ':editorFormFilterAdminFormatEditorConfigure', $form_state->getSubmitHandlers(), TRUE)) { // Ensure that plugins' validation constraints do not immediately // trigger a validation error: the user may choose to configure other // CKEditor 5 aspects first. Loading Loading @@ -907,9 +908,10 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s // @see ::validateConfigurationForm() $editor = $form_state->get('editor'); // Prepare the editor settings for editor_form_filter_admin_format_submit(). // Prepare settings for EditorHooks::editorFormFilterAdminFormatSubmit(). // This strips away unwanted form values too, because those never can exist // in the already validated Editor config entity. // @see \Drupal\editor\Hook\EditorHooks::editorFormFilterAdminFormatSubmit() $form_state->setValues($editor->getSettings()); parent::submitConfigurationForm($form, $form_state); Loading core/modules/editor/editor.module +0 −101 Changes for core/modules/editor/editor.module: 0 added lines, 101 removed lines. Original line number Diff line number Diff line Loading @@ -4,109 +4,8 @@ * @file */ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\SubformState; use Drupal\editor\Entity\Editor; use Drupal\filter\FilterFormatInterface; /** * Button submit handler for filter_format_form()'s 'editor_configure' button. */ function editor_form_filter_admin_format_editor_configure($form, FormStateInterface $form_state): void { $editor = $form_state->get('editor'); $editor_value = $form_state->getValue(['editor', 'editor']); if ($editor_value !== NULL) { if ($editor_value === '') { $form_state->set('editor', FALSE); $form_state->set('editor_plugin', NULL); } elseif (empty($editor) || $editor_value !== $editor->getEditor()) { $format = $form_state->getFormObject()->getEntity(); $editor = Editor::create([ 'format' => $format->isNew() ? NULL : $format->id(), 'editor' => $editor_value, 'image_upload' => [ 'status' => FALSE, ], ]); $form_state->set('editor', $editor); } } $form_state->setRebuild(); } /** * AJAX callback handler for filter_format_form(). */ function editor_form_filter_admin_form_ajax($form, FormStateInterface $form_state) { return $form['editor']['settings']; } /** * Additional validate handler for filter_format_form(). */ function editor_form_filter_admin_format_validate($form, FormStateInterface $form_state): void { $editor_set = $form_state->getValue(['editor', 'editor']) !== ""; $subform_array_exists = (!empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform'])); if ($editor_set && $subform_array_exists && $editor_plugin = $form_state->get('editor_plugin')) { $subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state); $editor_plugin->validateConfigurationForm($form['editor']['settings']['subform'], $subform_state); } // This validate handler is not applicable when using the 'Configure' button. if ($form_state->getTriggeringElement()['#name'] === 'editor_configure') { return; } // When using this form with JavaScript disabled in the browser, the // 'Configure' button won't be clicked automatically. So, when the user has // selected a text editor and has then clicked 'Save configuration', we should // point out that the user must still configure the text editor. if ($form_state->getValue(['editor', 'editor']) !== '' && !$form_state->get('editor')) { $form_state->setErrorByName('editor][editor', t('You must configure the selected text editor.')); } } /** * Additional submit handler for filter_format_form(). */ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_state): void { // Delete the existing editor if disabling or switching between editors. $format = $form_state->getFormObject()->getEntity(); $format_id = $format->isNew() ? NULL : $format->id(); $original_editor = $format_id ? Editor::load($format_id) : NULL; if ($original_editor && $original_editor->getEditor() != $form_state->getValue(['editor', 'editor'])) { $original_editor->delete(); } $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); } // Create a new editor or update the existing editor. if ($editor = $form_state->get('editor')) { // Ensure the text format is set: when creating a new text format, this // would equal the empty string. $editor->set('format', $format_id); if ($settings = $form_state->getValue(['editor', 'settings'])) { $editor->setSettings($settings); } // When image uploads are disabled (status = FALSE), the schema for image // upload settings does not allow other keys to be present. // @see editor.image_upload_settings.* // @see editor.image_upload_settings.1 // @see editor.schema.yml $image_upload_settings = $editor->getImageUploadSettings(); if (!$image_upload_settings['status']) { $editor->setImageUploadSettings(['status' => FALSE]); } $editor->save(); } } /** * Applies text editor XSS filtering. * Loading core/modules/editor/src/Hook/EditorHooks.php +123 −5 Changes for core/modules/editor/src/Hook/EditorHooks.php: 123 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state 'trigger_as' => [ 'name' => 'editor_configure', ], 'callback' => 'editor_form_filter_admin_form_ajax', 'callback' => self::class . ':editorFormFilterAdminFormAjax', 'wrapper' => 'editor-settings-wrapper', ], '#weight' => -10, Loading @@ -151,10 +151,10 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state ], ], '#submit' => [ 'editor_form_filter_admin_format_editor_configure', self::class . ':editorFormFilterAdminFormatEditorConfigure', ], '#ajax' => [ 'callback' => 'editor_form_filter_admin_form_ajax', 'callback' => self::class . ':editorFormFilterAdminFormAjax', 'wrapper' => 'editor-settings-wrapper', ], '#weight' => -10, Loading Loading @@ -185,8 +185,8 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state $form['editor']['settings']['subform'] = $plugin->buildConfigurationForm($form['editor']['settings']['subform'], $subform_state); $form['editor']['settings']['subform']['#parents'] = ['editor', 'settings']; } $form['#validate'][] = 'editor_form_filter_admin_format_validate'; $form['actions']['submit']['#submit'][] = 'editor_form_filter_admin_format_submit'; $form['#validate'][] = self::class . ':editorFormFilterAdminFormatValidate'; $form['actions']['submit']['#submit'][] = self::class . ':editorFormFilterAdminFormatSubmit'; } /** Loading Loading @@ -485,4 +485,122 @@ protected function parseFileUuids(string $text): array { return $uuids; } /** * Submit handler for 'editor_configure' button from 'filter_format_form'. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatEditorConfigure(array $form, FormStateInterface $form_state): void { $editor = $form_state->get('editor'); $editor_value = $form_state->getValue(['editor', 'editor']); if ($editor_value !== NULL) { if ($editor_value === '') { $form_state->set('editor', FALSE); $form_state->set('editor_plugin', NULL); } elseif (empty($editor) || $editor_value !== $editor->getEditor()) { $format = $form_state->getFormObject()->getEntity(); $editor = Editor::create([ 'format' => $format->isNew() ? NULL : $format->id(), 'editor' => $editor_value, 'image_upload' => [ 'status' => FALSE, ], ]); $form_state->set('editor', $editor); } } $form_state->setRebuild(); } /** * Ajax callback handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormAjax(array $form, FormStateInterface $form_state): array { return $form['editor']['settings']; } /** * Additional validate handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatValidate(array $form, FormStateInterface $form_state): void { $editor_set = $form_state->getValue(['editor', 'editor']) !== ""; $subform_array_exists = (!empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform'])); if ($editor_set && $subform_array_exists && $editor_plugin = $form_state->get('editor_plugin')) { $subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state); $editor_plugin->validateConfigurationForm($form['editor']['settings']['subform'], $subform_state); } // This validation handler should not be used with the 'Configure' button. if ($form_state->getTriggeringElement()['#name'] === 'editor_configure') { return; } // When using this form with JavaScript disabled in the browser, the // 'Configure' button won't be clicked automatically. So, when the user has // selected a text editor and has then clicked 'Save configuration', we // should point out that the user must still configure the text editor. if ($form_state->getValue(['editor', 'editor']) !== '' && !$form_state->get('editor')) { $form_state->setErrorByName('editor][editor', $this->t('You must configure the selected text editor.')); } } /** * Additional submit handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatSubmit(array $form, FormStateInterface $form_state): void { // Delete the existing editor if disabling or switching between editors. $format = $form_state->getFormObject()->getEntity(); $format_id = $format->isNew() ? NULL : $format->id(); $original_editor = $format_id ? Editor::load($format_id) : NULL; if ($original_editor && $original_editor->getEditor() != $form_state->getValue(['editor', 'editor'])) { $original_editor->delete(); } $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); } // Create a new editor or update the existing editor. if ($editor = $form_state->get('editor')) { // Ensure the text format is set: when creating a new text format, this // would equal the empty string. $editor->set('format', $format_id); if ($settings = $form_state->getValue(['editor', 'settings'])) { $editor->setSettings($settings); } // When image uploads are disabled (status = FALSE), the schema for image // upload settings does not allow other keys to be present. // @see editor.image_upload_settings.* // @see editor.image_upload_settings.1 // @see editor.schema.yml $image_upload_settings = $editor->getImageUploadSettings(); if (!$image_upload_settings['status']) { $editor->setImageUploadSettings(['status' => FALSE]); } $editor->save(); } } } Loading
core/.phpstan-baseline.php +0 −6 Changes for core/.phpstan-baseline.php: 0 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -14125,12 +14125,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php', ]; $ignoreErrors[] = [ 'message' => '#^Function editor_form_filter_admin_form_ajax\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', 'count' => 1, 'path' => __DIR__ . '/modules/editor/editor.module', ]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\editor\\\\Ajax\\\\EditorDialogSave\\:\\:render\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return',
core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php +3 −1 Changes for core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -522,7 +522,7 @@ public function filterFormatEditFormSubmit(array $form, FormStateInterface $form /** * AJAX callback handler for filter_format_form(). * * Used instead of editor_form_filter_admin_form_ajax from the editor module. * Used instead of EditorHooks::editorFormFilterAdminFormAjax(). * * @param array $form * The form render array. Loading @@ -531,6 +531,8 @@ public function filterFormatEditFormSubmit(array $form, FormStateInterface $form * * @return \Drupal\Core\Ajax\AjaxResponse * The Ajax response. * * @see \Drupal\editor\Hook\EditorHooks::editorFormFilterAdminFormAjax() */ public function updateCkeditor5HtmlFilter(array $form, FormStateInterface $form_state): AjaxResponse { $response = new AjaxResponse(); Loading
core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php +4 −2 Changes for core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php: 4 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ use Drupal\editor\Attribute\Editor; use Drupal\editor\EditorInterface; use Drupal\editor\Entity\Editor as EditorEntity; use Drupal\editor\Hook\EditorHooks; use Drupal\editor\Plugin\EditorBase; use Drupal\filter\FilterFormatInterface; use Psr\Log\LoggerInterface; Loading Loading @@ -661,7 +662,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form // Special case: AJAX updates that do not submit the form (that cannot // result in configuration being saved). if (in_array('editor_form_filter_admin_format_editor_configure', $form_state->getSubmitHandlers(), TRUE)) { if (in_array(EditorHooks::class . ':editorFormFilterAdminFormatEditorConfigure', $form_state->getSubmitHandlers(), TRUE)) { // Ensure that plugins' validation constraints do not immediately // trigger a validation error: the user may choose to configure other // CKEditor 5 aspects first. Loading Loading @@ -907,9 +908,10 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s // @see ::validateConfigurationForm() $editor = $form_state->get('editor'); // Prepare the editor settings for editor_form_filter_admin_format_submit(). // Prepare settings for EditorHooks::editorFormFilterAdminFormatSubmit(). // This strips away unwanted form values too, because those never can exist // in the already validated Editor config entity. // @see \Drupal\editor\Hook\EditorHooks::editorFormFilterAdminFormatSubmit() $form_state->setValues($editor->getSettings()); parent::submitConfigurationForm($form, $form_state); Loading
core/modules/editor/editor.module +0 −101 Changes for core/modules/editor/editor.module: 0 added lines, 101 removed lines. Original line number Diff line number Diff line Loading @@ -4,109 +4,8 @@ * @file */ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\SubformState; use Drupal\editor\Entity\Editor; use Drupal\filter\FilterFormatInterface; /** * Button submit handler for filter_format_form()'s 'editor_configure' button. */ function editor_form_filter_admin_format_editor_configure($form, FormStateInterface $form_state): void { $editor = $form_state->get('editor'); $editor_value = $form_state->getValue(['editor', 'editor']); if ($editor_value !== NULL) { if ($editor_value === '') { $form_state->set('editor', FALSE); $form_state->set('editor_plugin', NULL); } elseif (empty($editor) || $editor_value !== $editor->getEditor()) { $format = $form_state->getFormObject()->getEntity(); $editor = Editor::create([ 'format' => $format->isNew() ? NULL : $format->id(), 'editor' => $editor_value, 'image_upload' => [ 'status' => FALSE, ], ]); $form_state->set('editor', $editor); } } $form_state->setRebuild(); } /** * AJAX callback handler for filter_format_form(). */ function editor_form_filter_admin_form_ajax($form, FormStateInterface $form_state) { return $form['editor']['settings']; } /** * Additional validate handler for filter_format_form(). */ function editor_form_filter_admin_format_validate($form, FormStateInterface $form_state): void { $editor_set = $form_state->getValue(['editor', 'editor']) !== ""; $subform_array_exists = (!empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform'])); if ($editor_set && $subform_array_exists && $editor_plugin = $form_state->get('editor_plugin')) { $subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state); $editor_plugin->validateConfigurationForm($form['editor']['settings']['subform'], $subform_state); } // This validate handler is not applicable when using the 'Configure' button. if ($form_state->getTriggeringElement()['#name'] === 'editor_configure') { return; } // When using this form with JavaScript disabled in the browser, the // 'Configure' button won't be clicked automatically. So, when the user has // selected a text editor and has then clicked 'Save configuration', we should // point out that the user must still configure the text editor. if ($form_state->getValue(['editor', 'editor']) !== '' && !$form_state->get('editor')) { $form_state->setErrorByName('editor][editor', t('You must configure the selected text editor.')); } } /** * Additional submit handler for filter_format_form(). */ function editor_form_filter_admin_format_submit($form, FormStateInterface $form_state): void { // Delete the existing editor if disabling or switching between editors. $format = $form_state->getFormObject()->getEntity(); $format_id = $format->isNew() ? NULL : $format->id(); $original_editor = $format_id ? Editor::load($format_id) : NULL; if ($original_editor && $original_editor->getEditor() != $form_state->getValue(['editor', 'editor'])) { $original_editor->delete(); } $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); } // Create a new editor or update the existing editor. if ($editor = $form_state->get('editor')) { // Ensure the text format is set: when creating a new text format, this // would equal the empty string. $editor->set('format', $format_id); if ($settings = $form_state->getValue(['editor', 'settings'])) { $editor->setSettings($settings); } // When image uploads are disabled (status = FALSE), the schema for image // upload settings does not allow other keys to be present. // @see editor.image_upload_settings.* // @see editor.image_upload_settings.1 // @see editor.schema.yml $image_upload_settings = $editor->getImageUploadSettings(); if (!$image_upload_settings['status']) { $editor->setImageUploadSettings(['status' => FALSE]); } $editor->save(); } } /** * Applies text editor XSS filtering. * Loading
core/modules/editor/src/Hook/EditorHooks.php +123 −5 Changes for core/modules/editor/src/Hook/EditorHooks.php: 123 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -136,7 +136,7 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state 'trigger_as' => [ 'name' => 'editor_configure', ], 'callback' => 'editor_form_filter_admin_form_ajax', 'callback' => self::class . ':editorFormFilterAdminFormAjax', 'wrapper' => 'editor-settings-wrapper', ], '#weight' => -10, Loading @@ -151,10 +151,10 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state ], ], '#submit' => [ 'editor_form_filter_admin_format_editor_configure', self::class . ':editorFormFilterAdminFormatEditorConfigure', ], '#ajax' => [ 'callback' => 'editor_form_filter_admin_form_ajax', 'callback' => self::class . ':editorFormFilterAdminFormAjax', 'wrapper' => 'editor-settings-wrapper', ], '#weight' => -10, Loading Loading @@ -185,8 +185,8 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state $form['editor']['settings']['subform'] = $plugin->buildConfigurationForm($form['editor']['settings']['subform'], $subform_state); $form['editor']['settings']['subform']['#parents'] = ['editor', 'settings']; } $form['#validate'][] = 'editor_form_filter_admin_format_validate'; $form['actions']['submit']['#submit'][] = 'editor_form_filter_admin_format_submit'; $form['#validate'][] = self::class . ':editorFormFilterAdminFormatValidate'; $form['actions']['submit']['#submit'][] = self::class . ':editorFormFilterAdminFormatSubmit'; } /** Loading Loading @@ -485,4 +485,122 @@ protected function parseFileUuids(string $text): array { return $uuids; } /** * Submit handler for 'editor_configure' button from 'filter_format_form'. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatEditorConfigure(array $form, FormStateInterface $form_state): void { $editor = $form_state->get('editor'); $editor_value = $form_state->getValue(['editor', 'editor']); if ($editor_value !== NULL) { if ($editor_value === '') { $form_state->set('editor', FALSE); $form_state->set('editor_plugin', NULL); } elseif (empty($editor) || $editor_value !== $editor->getEditor()) { $format = $form_state->getFormObject()->getEntity(); $editor = Editor::create([ 'format' => $format->isNew() ? NULL : $format->id(), 'editor' => $editor_value, 'image_upload' => [ 'status' => FALSE, ], ]); $form_state->set('editor', $editor); } } $form_state->setRebuild(); } /** * Ajax callback handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormAjax(array $form, FormStateInterface $form_state): array { return $form['editor']['settings']; } /** * Additional validate handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatValidate(array $form, FormStateInterface $form_state): void { $editor_set = $form_state->getValue(['editor', 'editor']) !== ""; $subform_array_exists = (!empty($form['editor']['settings']['subform']) && is_array($form['editor']['settings']['subform'])); if ($editor_set && $subform_array_exists && $editor_plugin = $form_state->get('editor_plugin')) { $subform_state = SubformState::createForSubform($form['editor']['settings']['subform'], $form, $form_state); $editor_plugin->validateConfigurationForm($form['editor']['settings']['subform'], $subform_state); } // This validation handler should not be used with the 'Configure' button. if ($form_state->getTriggeringElement()['#name'] === 'editor_configure') { return; } // When using this form with JavaScript disabled in the browser, the // 'Configure' button won't be clicked automatically. So, when the user has // selected a text editor and has then clicked 'Save configuration', we // should point out that the user must still configure the text editor. if ($form_state->getValue(['editor', 'editor']) !== '' && !$form_state->get('editor')) { $form_state->setErrorByName('editor][editor', $this->t('You must configure the selected text editor.')); } } /** * Additional submit handler for 'filter_format_form' form. * * @param array $form * The form render array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. */ public function editorFormFilterAdminFormatSubmit(array $form, FormStateInterface $form_state): void { // Delete the existing editor if disabling or switching between editors. $format = $form_state->getFormObject()->getEntity(); $format_id = $format->isNew() ? NULL : $format->id(); $original_editor = $format_id ? Editor::load($format_id) : NULL; if ($original_editor && $original_editor->getEditor() != $form_state->getValue(['editor', 'editor'])) { $original_editor->delete(); } $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); } // Create a new editor or update the existing editor. if ($editor = $form_state->get('editor')) { // Ensure the text format is set: when creating a new text format, this // would equal the empty string. $editor->set('format', $format_id); if ($settings = $form_state->getValue(['editor', 'settings'])) { $editor->setSettings($settings); } // When image uploads are disabled (status = FALSE), the schema for image // upload settings does not allow other keys to be present. // @see editor.image_upload_settings.* // @see editor.image_upload_settings.1 // @see editor.schema.yml $image_upload_settings = $editor->getImageUploadSettings(); if (!$image_upload_settings['status']) { $editor->setImageUploadSettings(['status' => FALSE]); } $editor->save(); } } }