} // 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
// string '0', which could be a valid value.
$is_countable =
is_array($elements['#value'
]) ||
$elements['#value'
] instanceof \Countable;
$is_empty_multiple =
$is_countable &&
count($elements['#value'
]) == 0;
$is_empty_string =
(is_string($elements['#value'
]) &&
mb_strlen(trim($elements['#value'
])) == 0
);