Drupal 8  8.0.2
FormValidator Class Reference
Inheritance diagram for FormValidator:

Public Member Functions

 __construct (RequestStack $request_stack, TranslationInterface $string_translation, CsrfTokenGenerator $csrf_token, LoggerInterface $logger, FormErrorHandlerInterface $form_error_handler)
 
 executeValidateHandlers (&$form, FormStateInterface &$form_state)
 
 validateForm ($form_id, &$form, FormStateInterface &$form_state)
 
 setInvalidTokenError (FormStateInterface $form_state)
 

Protected Member Functions

 handleErrorsWithLimitedValidation (&$form, FormStateInterface &$form_state, $form_id)
 
 finalizeValidation (&$form, FormStateInterface &$form_state, $form_id)
 
 doValidateForm (&$elements, FormStateInterface &$form_state, $form_id=NULL)
 
 performRequiredValidation (&$elements, FormStateInterface &$form_state)
 
 determineLimitValidationErrors (FormStateInterface &$form_state)
 

Protected Attributes

 $csrfToken
 
 $requestStack
 
 $logger
 
 $formErrorHandler
 

Detailed Description

Provides validation of form submissions.

Constructor & Destructor Documentation

__construct ( RequestStack  $request_stack,
TranslationInterface  $string_translation,
CsrfTokenGenerator  $csrf_token,
LoggerInterface  $logger,
FormErrorHandlerInterface  $form_error_handler 
)

Constructs a new FormValidator.

Parameters
\Symfony\Component\HttpFoundation\RequestStack$request_stackThe request stack.
\Drupal\Core\StringTranslation\TranslationInterface$string_translationThe string translation service.
\Drupal\Core\Access\CsrfTokenGenerator$csrf_tokenThe CSRF token generator.
\Psr\Log\LoggerInterface$loggerA logger instance.
\Drupal\Core\Form\FormErrorHandlerInterface$form_error_handlerThe form error handler.

References Drupal\csrfToken(), Drupal\logger(), and Drupal\requestStack().

Here is the call graph for this function:

Member Function Documentation

determineLimitValidationErrors ( FormStateInterface $form_state)
protected

Determines if validation errors should be limited.

Parameters
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
array|null

References FormStateInterface\getTriggeringElement(), and FormStateInterface\isSubmitted().

Referenced by FormValidator\doValidateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

doValidateForm ( $elements,
FormStateInterface $form_state,
  $form_id = NULL 
)
protected

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.

Parameters
$elementsAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form. The current user-submitted data is stored in $form_state->getValues(), though form validation functions are passed an explicit copy of the values for the sake of simplicity. Validation handlers can also $form_state to pass information on to submit handlers. For example: $form_state->set('data_for_submission', $data); This technique is useful when validation requires file parsing, web service requests, or other expensive requests that should not be repeated in the submission step.
$form_idA unique string identifying the form for validation, submission, theming, and hook_form_alter functions.

References Element\children(), FormValidator\determineLimitValidationErrors(), FormValidator\executeValidateHandlers(), FormStateInterface\getCompleteForm(), FormValidator\performRequiredValidation(), FormStateInterface\prepareCallback(), FormStateInterface\setError(), FormStateInterface\setLimitValidationErrors(), Unicode\strlen(), and t().

Referenced by FormValidator\validateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
$formAn associative array containing the structure of the form.
$form_stateThe current state of the form. If the user submitted the form by clicking a button with custom handler functions defined, those handlers will be stored here.
}

Implements FormValidatorInterface.

References FormStateInterface\getValidateHandlers(), and FormStateInterface\prepareCallback().

Referenced by FormValidator\doValidateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

finalizeValidation ( $form,
FormStateInterface $form_state,
  $form_id 
)
protected

Finalizes validation.

Parameters
array$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
string$form_idThe unique string identifying the form.

References FormStateInterface\setValidationComplete().

Referenced by FormValidator\validateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

handleErrorsWithLimitedValidation ( $form,
FormStateInterface $form_state,
  $form_id 
)
protected

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.

Parameters
array$formAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
string$form_idThe unique string identifying the form.

References FormStateInterface\getTriggeringElement(), NestedArray\getValue(), FormStateInterface\getValue(), FormStateInterface\getValues(), NestedArray\keyExists(), NestedArray\setValue(), and FormStateInterface\setValues().

Referenced by FormValidator\validateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

performRequiredValidation ( $elements,
FormStateInterface $form_state 
)
protected

Performs validation of elements that are not subject to limited validation.

Parameters
array$elementsAn associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form. The current user-submitted data is stored in $form_state->getValues(), though form validation functions are passed an explicit copy of the values for the sake of simplicity. Validation handlers can also $form_state to pass information on to submit handlers. For example: $form_state->set('data_for_submission', $data); This technique is useful when validation requires file parsing, web service requests, or other expensive requests that should not be repeated in the submission step.

References OptGroup\flattenOptions(), Drupal\logger(), FormStateInterface\setError(), FormStateInterface\setValueForElement(), Unicode\strlen(), and t().

Referenced by FormValidator\doValidateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

setInvalidTokenError ( FormStateInterface  $form_state)

{Sets a form_token error on the given form state.

Parameters
\Drupal\Core\Form\FormStateInterface$form_stateThe current state of the form.
Returns
$this
}

Implements FormValidatorInterface.

References Drupal\requestStack(), FormStateInterface\setErrorByName(), and t().

Referenced by FormValidator\validateForm().

Here is the call graph for this function:

Here is the caller graph for this function:

validateForm (   $form_id,
$form,
FormStateInterface $form_state 
)

{Validates user-submitted form data in the $form_state.

Parameters
$form_idA unique string identifying the form for validation, submission, theming, and hook_form_alter functions.
$formAn associative array containing the structure of the form, which is passed by reference. Form validation handlers are able to alter the form structure (like #process and #after_build callbacks during form building) in case of a validation error. If a validation handler alters the form structure, it is responsible for validating the values of changed form elements in $form_state->getValues() to prevent form submit handlers from receiving unvalidated values.
$form_stateThe current state of the form. The current user-submitted data is stored in $form_state->getValues(), though form validation functions are passed an explicit copy of the values for the sake of simplicity. Validation handlers can also use $form_state to pass information on to submit handlers. For example: $form_state->set('data_for_submission', $data); This technique is useful when validation requires file parsing, web service requests, or other expensive requests that should not be repeated in the submission step.
}

Implements FormValidatorInterface.

References Drupal\csrfToken(), FormValidator\doValidateForm(), FormValidator\finalizeValidation(), FormStateInterface\getValue(), FormValidator\handleErrorsWithLimitedValidation(), FormStateInterface\hasInvalidToken(), FormStateInterface\isValidationComplete(), FormStateInterface\isValidationEnforced(), FormValidator\setInvalidTokenError(), and FormStateInterface\setValidationComplete().

Here is the call graph for this function:


The documentation for this class was generated from the following file: