Verified Commit f323ffae 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()

(cherry picked from commit b3ad3580)
parent d1ad71e7
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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));
+13 −0
Original line number Diff line number Diff line
@@ -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,
      ],
    ];
  }