You are here

public function UrlEmbedDialog::submitForm in URL Embed 8

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

src/Form/UrlEmbedDialog.php, line 152
Contains \Drupal\url_embed\Form\UrlEmbedDialog.

Class

UrlEmbedDialog
Provides a form to embed URLs.

Namespace

Drupal\url_embed\Form

Code

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

  // Display errors in form, if any.
  if ($form_state
    ->hasAnyErrors()) {
    unset($form['#prefix'], $form['#suffix']);
    $form['status_messages'] = array(
      '#type' => 'status_messages',
      '#weight' => -10,
    );
    $response
      ->addCommand(new HtmlCommand('#url-embed-dialog-form', $form));
  }
  else {
    $response
      ->addCommand(new EditorDialogSave($values));
    $response
      ->addCommand(new CloseModalDialogCommand());
  }
  return $response;
}