$elements_sorted =
$elements;
foreach (Element::
children($elements_sorted, TRUE
) as $key) { if (isset($elements[$key]) &&
$elements[$key]) { $this->
doValidateForm($elements[$key],
$form_state);
} } // Validate the current input.
if (!
isset($elements['#validated'
]) || !
$elements['#validated'
]) { // The following errors are always shown.
if (isset($elements['#needs_validation'
])) { $this->
performRequiredValidation($elements,
$form_state);
} // Set up the limited validation for errors.
$form_state->
setLimitValidationErrors($this->
determineLimitValidationErrors($form_state));
// Make sure a value is passed when the field is required.
if (isset($elements['#needs_validation'
]) &&
$elements['#required'
]) { // A simple call to empty() will not cut it here as some fields, like
// checkboxes, can return a valid value of '0'. Instead, check the
// length if it's a string, and the item count if it's an array.
// An unchecked checkbox has a #value of integer 0, different than