EditorImageDialog::submitForm

public EditorImageDialog::submitForm(array &$form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

core/modules/editor/src/Form/EditorImageDialog.php, line 200

Class

EditorImageDialog
Provides an image dialog for text editors.

Namespace

Drupal\editor\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $response = new AjaxResponse();

  // Convert any uploaded files from the FID values to data-entity-uuid
  // attributes and set data-entity-type to 'file'.
  $fid = $form_state->getValue(array('fid', 0));
  if (!empty($fid)) {
    $file = $this->fileStorage->load($fid);
    $file_url = file_create_url($file->getFileUri());
    // Transform absolute image URLs to relative image URLs: prevent problems
    // on multisite set-ups and prevent mixed content errors.
    $file_url = file_url_transform_relative($file_url);
    $form_state->setValue(array('attributes', 'src'), $file_url);
    $form_state->setValue(array('attributes', 'data-entity-uuid'), $file->uuid());
    $form_state->setValue(array('attributes', 'data-entity-type'), 'file');
  }

  // When the alt attribute is set to two double quotes, transform it to the
  // empty string: two double quotes signify "empty alt attribute". See above.
  if (trim($form_state->getValue(array('attributes', 'alt'))) === '""') {
    $form_state->setValue(array('attributes', 'alt'), '');
  }

  if ($form_state->getErrors()) {
    unset($form['#prefix'], $form['#suffix']);
    $form['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -10,
    ];
    $response->addCommand(new HtmlCommand('#editor-image-dialog-form', $form));
  }
  else {
    $response->addCommand(new EditorDialogSave($form_state->getValues()));
    $response->addCommand(new CloseModalDialogCommand());
  }

  return $response;
}
doc_Drupal
2016-10-29 09:03:49
Comments
Leave a Comment

Please login to continue.