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'] = '