FormValidator
class FormValidator implements FormValidatorInterface (View source)
Provides validation of form submissions.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Properties
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected CsrfTokenGenerator | $csrfToken | The CSRF token generator to validate the form token. |
|
| protected RequestStack | $requestStack | The request stack. |
|
| protected LoggerInterface | $logger | A logger instance. |
|
| protected FormErrorHandlerInterface | $formErrorHandler | The form error handler. |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a new FormValidator.
Executes custom validation handlers for a given form.
Validates user-submitted form data in the $form_state.
Sets a form_token error on the given form state.
Handles validation errors for forms with limited validation.
Finalizes validation.
Performs validation on form elements.
Performs validation of elements that are not subject to limited validation.
Determines if validation errors should be limited.
Details
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__construct(RequestStack $request_stack, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, FormErrorHandlerInterface $form_error_handler)
Constructs a new FormValidator.
executeValidateHandlers($form, FormStateInterface $form_state)
Executes custom validation handlers for a given form.
Button-specific handlers are checked first. If none exist, the function falls back to form-level handlers.
validateForm($form_id, $form, FormStateInterface $form_state)
Validates user-submitted form data in the $form_state.
$this
setInvalidTokenError(FormStateInterface $form_state)
Sets a form_token error on the given form state.
protected
handleErrorsWithLimitedValidation(array $form, FormStateInterface $form_state, string $form_id)
Handles validation errors for forms with limited validation.
If validation errors are limited then remove any non validated form values, so that only values that passed validation are left for submit callbacks.
protected
finalizeValidation(array $form, FormStateInterface $form_state, string $form_id)
Finalizes validation.
protected
doValidateForm($elements, FormStateInterface $form_state, $form_id = NULL)
Performs validation on form elements.
First ensures required fields are completed, #maxlength is not exceeded, and selected options were in the list of options given to the user. Then calls user-defined validators.
protected
performRequiredValidation(array $elements, FormStateInterface $form_state)
Performs validation of elements that are not subject to limited validation.
protected array|null
determineLimitValidationErrors(FormStateInterface $form_state)
Determines if validation errors should be limited.