public function YamlFormSubmissionForm::save in YAML Form 8
Form submission handler for the 'save' action.
Normally this method should be overridden to provide specific messages to the user and redirect the form after the entity has been saved.
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
int Either SAVED_NEW or SAVED_UPDATED, depending on the operation performed.
Overrides EntityForm::save
2 calls to YamlFormSubmissionForm::save()
- YamlFormSubmissionForm::autosave in src/
YamlFormSubmissionForm.php - Form submission handler to autosave when there are validation errors.
- YamlFormSubmissionForm::wizardSubmit in src/
YamlFormSubmissionForm.php - Form submission handler for the wizard submit action.
File
- src/
YamlFormSubmissionForm.php, line 813
Class
- YamlFormSubmissionForm
- Provides a form to collect and edit submissions.
Namespace
Drupal\yamlformCode
public function save(array $form, FormStateInterface $form_state) {
$yamlform = $this
->getYamlForm();
/** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
$yamlform_submission = $this
->getEntity();
// Set current page.
if ($current_page = $this
->getCurrentPage($form, $form_state)) {
$yamlform_submission
->setCurrentPage($current_page);
}
// Make sure the uri and remote addr are set correctly because
// AJAX requests via 'managed_file' uploads can cause these values to be
// reset.
if ($yamlform_submission
->isNew()) {
$yamlform_submission
->set('uri', preg_replace('#^' . base_path() . '#', '/', $this
->getRequest()
->getRequestUri()));
$yamlform_submission
->set('remote_addr', $this
->isConfidential() ? '' : $this
->getRequest()
->getClientIp());
}
// Block users from submitting templates that they can't update.
if ($yamlform
->isTemplate() && !$yamlform
->access('update')) {
return;
}
// Save and log form submission.
$yamlform_submission
->save();
// Check limits and invalidate cached and rebuild.
if ($this
->checkTotalLimit() || $this
->checkUserLimit()) {
Cache::invalidateTags([
'yamlform:' . $this
->getYamlForm()
->id(),
]);
$form_state
->setRebuild();
}
}