public function WebformSubmissionForm::autosave in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::autosave()
Webform submission handler to autosave when there are validation errors.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
File
- src/
WebformSubmissionForm.php, line 1668
Class
- WebformSubmissionForm
- Provides a webform to collect and edit submissions.
Namespace
Drupal\webformCode
public function autosave(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasAnyErrors()) {
if ($this
->draftEnabled() && $this
->getWebformSetting('draft_auto_save') && !$this->entity
->isCompleted()) {
$form_state
->set('in_draft', TRUE);
$was_new = $this->entity
->isNew();
$this
->submitForm($form, $form_state);
$this
->save($form, $form_state);
$this
->rebuild($form, $form_state);
if ($was_new && $form_state
->hasAnyErrors()) {
// Prevent the previously-cached form object, which is stored in
// $form['build_info']['callback_object'] from being used because it
// refers to the original new (unsaved) entity.
$this->formBuilder
->deleteCache($form['#build_id']);
}
}
}
}