Skip to content
Snippets Groups Projects
Verified Commit b3ad3580 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3447748 by joelpittet, ramil g, smustgrave: TypeError: Illegal offset...

Issue #3447748 by joelpittet, ramil g, smustgrave: TypeError: Illegal offset type in isset or empty in FormValidator->performRequiredValidation()
parent 5a9e57dc
No related branches found
No related tags found
No related merge requests found
......@@ -345,6 +345,12 @@ protected function performRequiredValidation(&$elements, FormStateInterface &$fo
if (is_array($elements['#value'])) {
$value = in_array($elements['#type'], ['checkboxes', 'tableselect']) ? array_keys($elements['#value']) : $elements['#value'];
foreach ($value as $v) {
if (!is_scalar($v)) {
$message_arguments['%type'] = gettype($v);
$form_state->setError($elements, $this->t('The submitted value type %type in the %name element is not allowed.', $message_arguments));
$this->logger->error('The submitted value type %type in the %name element is not allowed.', $message_arguments);
continue;
}
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));
......
......@@ -462,6 +462,19 @@ public static function providerTestPerformRequiredValidation() {
'Test cannot be longer than <em class="placeholder">7</em> characters but is currently <em class="placeholder">8</em> characters long.',
FALSE,
],
[
[
'#type' => 'select',
'#options' => [
'foo' => 'Foo',
'bar' => 'Bar',
],
'#value' => [[]],
'#multiple' => TRUE,
],
'The submitted value type <em class="placeholder">array</em> in the <em class="placeholder">Test</em> element is not allowed.',
TRUE,
],
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment