class AutosaveFormValidator in Autosave Form 8
Provides validation of form submissions with AutosaveForm enabled.
Hierarchy
- class \Drupal\Core\Form\FormValidator implements FormValidatorInterface uses StringTranslationTrait
- class \Drupal\autosave_form\Form\AutosaveFormValidator uses AutosaveButtonClickedTrait
Expanded class hierarchy of AutosaveFormValidator
1 string reference to 'AutosaveFormValidator'
1 service uses AutosaveFormValidator
File
- src/
Form/ AutosaveFormValidator.php, line 17
Namespace
Drupal\autosave_form\FormView source
class AutosaveFormValidator extends FormValidator {
use AutosaveButtonClickedTrait;
/**
* The form validator service.
*
* @var \Drupal\Core\Form\FormValidatorInterface
*/
protected $formValidator;
/**
* Constructs a AutosaveFormValidator object.
*
* @param \Drupal\Core\Form\FormValidatorInterface $form_validator
* The form validator service.
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The request stack.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
* The CSRF token generator.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Form\FormErrorHandlerInterface $form_error_handler
* The form error handler.
*/
public function __construct(FormValidatorInterface $form_validator, RequestStack $request_stack, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, FormErrorHandlerInterface $form_error_handler) {
$this->formValidator = $form_validator;
parent::__construct($request_stack, $string_translation, $csrf_token, $logger, $form_error_handler);
}
/**
* {@inheritdoc}
*/
public function validateForm($form_id, &$form, FormStateInterface &$form_state) {
$autosave_submission = $this
->isAutosaveTriggered($form_state);
if ($autosave_submission) {
// On subsequent autosaving we don't need to execute the form validation
// as we are not going to build the intermediate entity. However it might
// happen that between here and the autosave submission handler the
// autosaved state has been purged and therefore we have to check
// explicitly for that there instead of building the intermediate entity.
$form_state
->setTemporaryValue('autosave_form_form_validation_skipped', TRUE);
}
else {
// We have to execute the validation in the case of autosave submission
// for the very first time as in this case we'll build the intermediate
// entity for comparison and some input values are being prepared in the
// validate functions. This is the case with e.g. autocomplete for entity
// references.
$this->formValidator
->validateForm($form_id, $form, $form_state);
}
// In order for the autosave submit callback to be executed we have to
// clear the errors caused from the validation, otherwise no submit
// callbacks will be executed.
if ($autosave_submission && $form_state::hasAnyErrors()) {
$form_state
->clearErrors();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AutosaveButtonClickedTrait:: |
protected | function | Checks if the submission is triggered by autosave save. | |
AutosaveButtonClickedTrait:: |
protected | function | Checks if autosave restore has been triggered. | |
AutosaveButtonClickedTrait:: |
protected | function | Checks if autosave restore has been triggered. | |
AutosaveFormValidator:: |
protected | property | The form validator service. | |
AutosaveFormValidator:: |
public | function |
Validates user-submitted form data in the $form_state. Overrides FormValidator:: |
|
AutosaveFormValidator:: |
public | function |
Constructs a AutosaveFormValidator object. Overrides FormValidator:: |
|
FormValidator:: |
protected | property | The CSRF token generator to validate the form token. | |
FormValidator:: |
protected | property | The form error handler. | |
FormValidator:: |
protected | property | A logger instance. | |
FormValidator:: |
protected | property | The request stack. | |
FormValidator:: |
protected | function | Determines if validation errors should be limited. | |
FormValidator:: |
protected | function | Performs validation on form elements. | |
FormValidator:: |
public | function |
Executes custom validation handlers for a given form. Overrides FormValidatorInterface:: |
|
FormValidator:: |
protected | function | Finalizes validation. | |
FormValidator:: |
protected | function | Handles validation errors for forms with limited validation. | |
FormValidator:: |
protected | function | Performs validation of elements that are not subject to limited validation. | |
FormValidator:: |
public | function |
Sets a form_token error on the given form state. Overrides FormValidatorInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |