public function WebformSubmissionForm::reset in Webform 6.x
Same name and namespace in other branches
- 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::reset()
Webform submission handler for the 'reset' action.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
1 call to WebformSubmissionForm::reset()
- WebformSubmissionForm::confirmForm in src/
WebformSubmissionForm.php - Webform confirm(ation) handler.
File
- src/
WebformSubmissionForm.php, line 1934
Class
- WebformSubmissionForm
- Provides a webform to collect and edit submissions.
Namespace
Drupal\webformCode
public function reset(array &$form, FormStateInterface $form_state) {
// Delete save draft.
/** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */
$webform_submission = $this
->getEntity();
if ($webform_submission
->isDraft()) {
$webform_submission
->delete();
}
// Create new webform submission.
/** @var \Drupal\webform\Entity\WebformSubmission $webform_submission */
$webform_submission = $this
->getEntity()
->createDuplicate();
$webform_submission
->setData($this->originalData);
$this
->setEntity($webform_submission);
// Reset user input but preserve form tokens.
$form_state
->setUserInput(array_intersect_key($form_state
->getUserInput(), [
'form_build_id' => 'form_build_id',
'form_token' => 'form_token',
'form_id' => 'form_id',
]));
// Reset values.
$form_state
->setValues([]);
// Reset current page.
$storage = $form_state
->getStorage();
unset($storage['current_page']);
$form_state
->setStorage($storage);
// Rebuild the form.
$this
->rebuild($form, $form_state);
}