diff --git a/core/modules/ckeditor/js/views/ControllerView.js b/core/modules/ckeditor/js/views/ControllerView.js index e6cbe24b8d2f3055d1ede120f79bb04eaa44053e..0f48373a79f8e2770513324d1d19b946797183f0 100644 --- a/core/modules/ckeditor/js/views/ControllerView.js +++ b/core/modules/ckeditor/js/views/ControllerView.js @@ -144,7 +144,7 @@ }; // Create hidden CKEditor with all features enabled, retrieve metadata. - // @see \Drupal\ckeditor\Plugin\Editor\CKEditor::settingsForm. + // @see \Drupal\ckeditor\Plugin\Editor\CKEditor::buildConfigurationForm(). var hiddenCKEditorID = 'ckeditor-hidden'; if (CKEDITOR.instances[hiddenCKEditorID]) { CKEDITOR.instances[hiddenCKEditorID].destroy(true); diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 010177974405a17f28308318969acce97c570b56..8df1f0460a9d494b7da590eb4e6c6dd3c30bdff2 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -168,12 +168,13 @@ function editor_form_filter_format_form_alter(&$form, FormStateInterface $form_s // Add editor-specific validation and submit handlers. if ($editor) { + /** @var $plugin \Drupal\editor\Plugin\EditorPluginInterface */ $plugin = $manager->createInstance($editor->getEditor()); $settings_form = array(); - $settings_form['#element_validate'][] = array($plugin, 'settingsFormValidate'); - $form['editor']['settings']['subform'] = $plugin->settingsForm($settings_form, $form_state, $editor); + $settings_form['#element_validate'][] = array($plugin, 'validateConfigurationForm'); + $form['editor']['settings']['subform'] = $plugin->buildConfigurationForm($settings_form, $form_state); $form['editor']['settings']['subform']['#parents'] = array('editor', 'settings'); - $form['actions']['submit']['#submit'][] = array($plugin, 'settingsFormSubmit'); + $form['actions']['submit']['#submit'][] = array($plugin, 'submitConfigurationForm'); } $form['#validate'][] = 'editor_form_filter_admin_format_validate'; diff --git a/core/modules/editor/src/Plugin/EditorBase.php b/core/modules/editor/src/Plugin/EditorBase.php index 6d906eae09fe80c8bfe427e5b543b3ba7f2c02f5..bd429d1376d042686a6ef4b336bd12b9d1a1649d 100644 --- a/core/modules/editor/src/Plugin/EditorBase.php +++ b/core/modules/editor/src/Plugin/EditorBase.php @@ -31,21 +31,51 @@ public function getDefaultSettings() { /** * {@inheritdoc} + * + * @todo Remove in Drupal 9.0.0. */ public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) { + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.3.x and will be removed in 9.0.0.', E_USER_DEPRECATED); return $form; } /** * {@inheritdoc} + * + * @todo Remove in Drupal 9.0.0. */ public function settingsFormValidate(array $form, FormStateInterface $form_state) { + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.3.x and will be removed in 9.0.0.', E_USER_DEPRECATED); } /** * {@inheritdoc} + * + * @todo Remove in Drupal 9.0.0. */ public function settingsFormSubmit(array $form, FormStateInterface $form_state) { + @trigger_error('The ' . __METHOD__ . ' method is deprecated since version 8.3.x and will be removed in 9.0.0.', E_USER_DEPRECATED); + } + + /** + * {@inheritdoc} + */ + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + return $this->settingsForm($form, $form_state, $form_state->get('editor')); + } + + /** + * {@inheritdoc} + */ + public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { + return $this->settingsFormValidate($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + return $this->settingsFormSubmit($form, $form_state); } } diff --git a/core/modules/editor/src/Plugin/EditorPluginInterface.php b/core/modules/editor/src/Plugin/EditorPluginInterface.php index a1a67597445cbccc6296dcda9c9119382a903083..fa9d2ad2b2d028e446cf33e53d10ec13a896aa67 100644 --- a/core/modules/editor/src/Plugin/EditorPluginInterface.php +++ b/core/modules/editor/src/Plugin/EditorPluginInterface.php @@ -3,7 +3,7 @@ namespace Drupal\editor\Plugin; use Drupal\Component\Plugin\PluginInspectionInterface; -use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Plugin\PluginFormInterface; use Drupal\editor\Entity\Editor; /** @@ -12,12 +12,17 @@ * Modules implementing this interface may want to extend the EditorBase class, * which provides default implementations of each method where appropriate. * + * If the editor's behavior depends on extensive options and/or external data, + * then the implementing module can choose to provide a separate, global + * configuration page rather than per-text-format settings. In that case, this + * form should provide a link to the separate settings page. + * * @see \Drupal\editor\Annotation\Editor * @see \Drupal\editor\Plugin\EditorBase * @see \Drupal\editor\Plugin\EditorManager * @see plugin_api */ -interface EditorPluginInterface extends PluginInspectionInterface { +interface EditorPluginInterface extends PluginInspectionInterface, PluginFormInterface { /** * Returns the default settings for this configurable text editor. @@ -28,53 +33,6 @@ interface EditorPluginInterface extends PluginInspectionInterface { */ public function getDefaultSettings(); - /** - * Returns a settings form to configure this text editor. - * - * If the editor's behavior depends on extensive options and/or external data, - * then the implementing module can choose to provide a separate, global - * configuration page rather than per-text-format settings. In that case, this - * form should provide a link to the separate settings page. - * - * @param array $form - * An empty form array to be populated with a configuration form, if any. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The state of the entire filter administration form. - * @param \Drupal\editor\Entity\Editor $editor - * A configured text editor object. - * - * @return array - * A render array for the settings form. - */ - public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor); - - /** - * Validates the settings form for an editor. - * - * The contents of the editor settings are located in - * $form_state->getValue(array('editor', 'settings')). Calls to $form_state->setError() - * should reflect this location in the settings form. - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - public function settingsFormValidate(array $form, FormStateInterface $form_state); - - /** - * Modifies any values in the form state to prepare them for saving. - * - * Values in $form_state->getValue(array('editor', 'settings')) are saved by - * Editor module in editor_form_filter_admin_format_submit(). - * - * @param array $form - * An associative array containing the structure of the form. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - public function settingsFormSubmit(array $form, FormStateInterface $form_state); - /** * Returns JavaScript settings to be attached. * diff --git a/core/modules/editor/tests/src/Unit/EditorBaseTest.php b/core/modules/editor/tests/src/Unit/EditorBaseTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a088fb054c1407232da8557c8720a1e8891a36ac --- /dev/null +++ b/core/modules/editor/tests/src/Unit/EditorBaseTest.php @@ -0,0 +1,75 @@ +<?php + +namespace Drupal\Tests\editor\Unit; + +use Drupal\Core\Form\FormState; +use Drupal\Core\Form\FormStateInterface; +use Drupal\editor\Entity\Editor; +use Drupal\editor\Plugin\EditorBase; +use Drupal\Tests\UnitTestCase; + +/** + * @coversDefaultClass \Drupal\editor\Plugin\EditorBase + * @group editor + */ +class EditorBaseTest extends UnitTestCase { + + /** + * @covers ::buildConfigurationForm + * @covers ::validateConfigurationForm + * @covers ::submitConfigurationForm + */ + public function testBc() { + $form_state = new FormState(); + $form_state->set('editor', $this->prophesize(Editor::class)->reveal()); + $editor_plugin = new BcEditor([], 'editor_plugin', []); + + // settingsForm() is deprecated in favor of buildConfigurationForm(). + $this->assertSame( + $editor_plugin->settingsForm([], clone $form_state, $this->prophesize(Editor::class)->reveal()), + $editor_plugin->buildConfigurationForm([], clone $form_state) + ); + + // settingsFormValidate() is deprecated in favor of + // validateConfigurationForm(). + $form = []; + $form_state_a = clone $form_state; + $form_state_b = clone $form_state; + $editor_plugin->settingsFormValidate($form, $form_state_a, $this->prophesize(Editor::class)->reveal()); + $editor_plugin->validateConfigurationForm($form, $form_state_b); + $this->assertEquals($form_state_a, $form_state_b); + + // settingsFormSubmit() is deprecated in favor of submitConfigurationForm(). + $form = []; + $form_state_a = clone $form_state; + $form_state_b = clone $form_state; + $editor_plugin->settingsFormSubmit($form, $form_state_a, $this->prophesize(Editor::class)->reveal()); + $editor_plugin->submitConfigurationForm($form, $form_state_b); + $this->assertEquals($form_state_a, $form_state_b); + } + +} + +class BcEditor extends EditorBase { + + public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) { + return ['foo' => 'bar']; + } + + public function settingsFormValidate(array $form, FormStateInterface $form_state) { + $form_state->setValue('foo', 'bar'); + } + + public function settingsFormSubmit(array $form, FormStateInterface $form_state) { + $form_state->setValue('bar', 'baz'); + } + + public function getJSSettings(Editor $editor) { + return []; + } + + public function getLibraries(Editor $editor) { + return []; + } + +}