public function FormSubmitter::doSubmitForm

public FormSubmitter::doSubmitForm(&$form, FormStateInterface &$form_state)

Handles the submitted form, executing callbacks and processing responses.

Parameters

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

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

Return value

null|\Symfony\Component\HttpFoundation\Response If a response was set by a submit handler, or if the form needs to redirect, a Response object will be returned.

Overrides FormSubmitterInterface::doSubmitForm

File

core/lib/Drupal/Core/Form/FormSubmitter.php, line 45

Class

FormSubmitter
Provides submission processing for forms.

Namespace

Drupal\Core\Form

Code

public function doSubmitForm(&$form, FormStateInterface &$form_state) {
  if (!$form_state->isSubmitted()) {
    return;
  }

  // Execute form submit handlers.
  $this->executeSubmitHandlers($form, $form_state);

  // If batches were set in the submit handlers, we process them now,
  // possibly ending execution. We make sure we do not react to the batch
  // that is already being processed (if a batch operation performs a
  // \Drupal\Core\Form\FormBuilderInterface::submitForm).
  if ($batch = & $this->batchGet() && !isset($batch['current_set'])) {
    // Store $form_state information in the batch definition.
    $batch['form_state'] = $form_state;

    $batch['progressive'] = !$form_state->isProgrammed();
    $response = batch_process();
    if ($batch['progressive']) {
      return $response;
    }

    // Execution continues only for programmatic forms.
    // For 'regular' forms, we get redirected to the batch processing
    // page. Form redirection will be handled in _batch_finished(),
    // after the batch is processed.
  }

  // Set a flag to indicate the form has been processed and executed.
  $form_state->setExecuted();

  // If no response has been set, process the form redirect.
  if (!$form_state->getResponse() && $redirect = $this->redirectForm($form_state)) {
    $form_state->setResponse($redirect);
  }

  // If there is a response was set, return it instead of continuing.
  if (($response = $form_state->getResponse()) && $response instanceof Response) {
    return $response;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormSubmitter.php/function/FormSubmitter::doSubmitForm/8.1.x