W3cubDocs

/Drupal 8

protected function FormValidator::determineLimitValidationErrors

protected FormValidator::determineLimitValidationErrors(FormStateInterface &$form_state)

Determines if validation errors should be limited.

Parameters

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array|null

File

core/lib/Drupal/Core/Form/FormValidator.php, line 376

Class

FormValidator
Provides validation of form submissions.

Namespace

Drupal\Core\Form

Code

protected function determineLimitValidationErrors(FormStateInterface &$form_state) {
  // While this element is being validated, it may be desired that some
  // calls to \Drupal\Core\Form\FormStateInterface::setErrorByName() be
  // suppressed and not result in a form error, so that a button that
  // implements low-risk functionality (such as "Previous" or "Add more") that
  // doesn't require all user input to be valid can still have its submit
  // handlers triggered. The triggering element's #limit_validation_errors
  // property contains the information for which errors are needed, and all
  // other errors are to be suppressed. The #limit_validation_errors property
  // is ignored if submit handlers will run, but the element doesn't have a
  // #submit property, because it's too large a security risk to have any
  // invalid user input when executing form-level submit handlers.
  $triggering_element = $form_state->getTriggeringElement();
  if (isset($triggering_element['#limit_validation_errors']) && ($triggering_element['#limit_validation_errors'] !== FALSE) && !($form_state->isSubmitted() && !isset($triggering_element['#submit']))) {
    return $triggering_element['#limit_validation_errors'];
  }
  // If submit handlers won't run (due to the submission having been
  // triggered by an element whose #executes_submit_callback property isn't
  // TRUE), then it's safe to suppress all validation errors, and we do so
  // by default, which is particularly useful during an Ajax submission
  // triggered by a non-button. An element can override this default by
  // setting the #limit_validation_errors property. For button element
  // types, #limit_validation_errors defaults to FALSE, so that full
  // validation is their default behavior.
  elseif ($triggering_element && !isset($triggering_element['#limit_validation_errors']) && !$form_state->isSubmitted()) {
    return array();
  }
  // As an extra security measure, explicitly turn off error suppression if
  // one of the above conditions wasn't met. Since this is also done at the
  // end of this function, doing it here is only to handle the rare edge
  // case where a validate handler invokes form processing of another form.
  else {
    return NULL;
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormValidator.php/function/FormValidator::determineLimitValidationErrors/8.1.x