diff --git a/core/modules/editor/src/Form/EditorImageDialog.php b/core/modules/editor/src/Form/EditorImageDialog.php index 9c2feb5..1075852 100644 --- a/core/modules/editor/src/Form/EditorImageDialog.php +++ b/core/modules/editor/src/Form/EditorImageDialog.php @@ -63,14 +63,22 @@ public function getFormId() { * The filter format for which this dialog corresponds. */ public function buildForm(array $form, FormStateInterface $form_state, FilterFormat $filter_format = NULL) { - // The default values are set directly from \Drupal::request()->request, - // provided by the editor plugin opening the dialog. - if (!$image_element = $form_state->get('image_element')) { - $user_input = $form_state->getUserInput(); - $image_element = isset($user_input['editor_object']) ? $user_input['editor_object'] : []; - $form_state->set('image_element', $image_element); + // This form is special, in that the default values do not come from the + // server side, but from the client side, from a text editor. We must cache + // this data in form state, because when the form is rebuilt, we will be + // receiving values from the form, instead of the values from the text + // editor. If we don't cache it, this data will be lost. + if (isset($form_state->getUserInput()['editor_object'])) { + // By convention, the data that the text editor sends to any dialog is in + // the 'editor_object' key. And the image dialog for text editors expects + // that data to be the attributes for an element. + $form_state->set('image_element', $form_state->getUserInput()['editor_object']); + $form_state->setCached(TRUE); } + // Retrieve the image element's attributes from form state. + $image_element = $form_state->get('image_element'); + $form['#tree'] = TRUE; $form['#attached']['library'][] = 'editor/drupal.editor.dialog'; $form['#prefix'] = '
'; diff --git a/core/modules/editor/src/Tests/EditorImageDialogTest.php b/core/modules/editor/src/Tests/EditorImageDialogTest.php index 33e00ca..8350ea7 100644 --- a/core/modules/editor/src/Tests/EditorImageDialogTest.php +++ b/core/modules/editor/src/Tests/EditorImageDialogTest.php @@ -49,7 +49,7 @@ class EditorImageDialogTest extends EntityUnitTestBase { protected function setUp() { parent::setUp(); $this->installEntitySchema('file'); - $this->installSchema('system', ['router']); + $this->installSchema('system', ['router', 'key_value_expire']); $this->installSchema('node', array('node_access')); $this->installSchema('file', array('file_usage')); $this->installConfig(['node']); @@ -123,10 +123,7 @@ public function testEditorImageDialog() { $request_stack->push($request); $form_builder = $this->container->get('form_builder'); $form_object = new EditorImageDialog(\Drupal::entityManager()->getStorage('file')); - $form_id = $form_builder->getFormId($form_object, $form_state); - $form = $form_builder->retrieveForm($form_id, $form_state); - $form_builder->prepareForm($form_id, $form, $form_state); - $form_builder->processForm($form_id, $form, $form_state); + $form_builder->buildForm($form_object, $form_state); // Assert these two values are present and we don't get the 'not-this' // default back.