You are here

public function EntityEmbedDialog::submitSelectStep in Entity Embed 8

Form submission handler for the entity selection step.

On success will send the user to the next step of the form to select the embed display settings. On form errors, this will rebuild the form and display the error messages.

Parameters

array $form: The form array.

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

Return value

\Drupal\Core\Ajax\AjaxResponse The ajax response.

File

src/Form/EntityEmbedDialog.php, line 712

Class

EntityEmbedDialog
Provides a form to embed entities by specifying data attributes.

Namespace

Drupal\entity_embed\Form

Code

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

  // Display errors in form, if any.
  if ($form_state
    ->hasAnyErrors()) {
    unset($form['#prefix'], $form['#suffix']);
    $form['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -10,
    ];
    $response
      ->addCommand(new HtmlCommand('#entity-embed-dialog-form', $form));
  }
  else {
    $form_state
      ->set('step', !empty($this->entityBrowserSettings['display_review']) ? 'review' : 'embed');
    $form_state
      ->setRebuild(TRUE);
    $rebuild_form = $this->formBuilder
      ->rebuildForm('entity_embed_dialog', $form_state, $form);
    unset($rebuild_form['#prefix'], $rebuild_form['#suffix']);
    $response
      ->addCommand(new HtmlCommand('#entity-embed-dialog-form', $rebuild_form));
    $response
      ->addCommand(new SetDialogTitleCommand('', $rebuild_form['#title']));
  }
  return $response;
}