You are here

public function AutosaveFormBuilder::processForm in Autosave Form 8

Processes a form submission.

This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted and rebuilt.

Parameters

string $form_id: The unique string identifying the current form.

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

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. This includes the current persistent storage data for the form, and any data passed along by earlier steps when displaying a multi-step form. Additional information, like the sanitized \Drupal::request()->request data, is also accumulated here.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse|null

Overrides FormBuilder::processForm

File

src/Form/AutosaveFormBuilder.php, line 127

Class

AutosaveFormBuilder
Provides form building and processing with AutosaveForm enabled.

Namespace

Drupal\autosave_form\Form

Code

public function processForm($form_id, &$form, FormStateInterface &$form_state) {
  if ($this
    ->isAutosaveTriggered($form_state)) {

    // @todo should we add a condition, that the form state is already cached
    // in order to stop fully processing the form?
    $this->doBuildFormSkip = TRUE;

    // As we'll skip doBuildForm we have to take care of setting the
    // triggering element.
    $form_state
      ->setTriggeringElement($form[AutosaveFormInterface::AUTOSAVE_ELEMENT_NAME]);

    // Needed to execute the submit handler, as this will not be done if
    // duBuildForm is not being executed.
    $form_state
      ->setSubmitHandlers($form[AutosaveFormInterface::AUTOSAVE_ELEMENT_NAME]['#submit']);
    $form_state
      ->setProcessInput();
    $form_state
      ->setSubmitted();
  }
  $response = parent::processForm($form_id, $form, $form_state);
  $this->doBuildFormSkip = FALSE;
  return $response;
}