TypeError: Argument 1 passed to Drupal\Core\Form\FormState::setError() must be of the type array, string given

Created on 18 May 2021, over 3 years ago
Updated 16 January 2024, 9 months ago

Problem/Motivation

When a previous button is implemented and no fields are filled in on the current step of the form, an error is triggered as stated in the title.

The full error log is as follows:

TypeError: Argument 1 passed to Drupal\Core\Form\FormState::setError() must be of the type array, string given, called in /var/www/html/docroot/modules/contrib/multistep_form_framework/src/Form/MultiStepFormBase.php on line 260 in Drupal\Core\Form\FormState->setError() (line 1093 of /var/www/html/docroot/core/lib/Drupal/Core/Form/FormState.php)
#0 /var/www/html/docroot/modules/contrib/multistep_form_framework/src/Form/MultiStepFormBase.php(260): Drupal\Core\Form\FormState->setError('field_horse_typ...', Object(Drupal\Core\StringTranslation\TranslatableMarkup))

Rather than the form element being passed to FormState_setError, only the field name is being passed and so the error is triggered. This is fixed by simply changing $form_state->setError to $form_state->setErrorByName. Will attach a patch.

πŸ› Bug report
Status

Closed: outdated

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom welly

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024