protected function performRequiredValidation(&
$elements, FormStateInterface &
$form_state) { // Verify that the value is not longer than #maxlength.
if (isset($elements['#maxlength'
]) &&
mb_strlen($elements['#value'
]) >
$elements['#maxlength'
]) { $form_state->
setError($elements,
$this->
t('@name cannot be longer than %max characters but is currently %length characters long.',
['@name' =>
empty($elements['#title'
]) ?
$elements['#parents'
][0
] :
$elements['#title'
], '%max' =>
$elements['#maxlength'
], '%length' =>
mb_strlen($elements['#value'
])]));
} if (isset($elements['#options'
]) &&
isset($elements['#value'
])) { $name =
empty($elements['#title'
]) ?
$elements['#parents'
][0
] :
$elements['#title'
];
$message_arguments =
['%name' =>
$name];
if ($elements['#type'
] == 'select'
) { $options = OptGroup::
flattenOptions($elements['#options'
]);
} else { $options =
$elements['#options'
];
} if (is_array($elements['#value'
])) { $value =
in_array($elements['#type'
],
['checkboxes', 'tableselect'
]) ?
array_keys($elements['#value'
]) :
$elements['#value'
];
foreach ($value as $v) { if (!
isset($options[$v])) { $message_arguments['%choice'
] =
$v;
$form_state->
setError($elements,
$this->
t('The submitted value %choice in the %name element is not allowed.',
$message_arguments));
$this->logger->
error('The submitted value %choice in the %name element is not allowed.',
$message_arguments);
}