Follow-up for #3382510: FormStateInterface::setErrorByName() needs not #name but a variation

Created on 3 November 2023, about 1 year ago
Updated 6 November 2023, about 1 year ago

Problem/Motivation

πŸ“Œ Introduce a new #config_target Form API property to make it super simple to use validation constraints on simple config forms, and adopt it in several core config forms Fixed landed, yay! Unfortunately it introduced a regression πŸ›

So I tried adopting it in my contrib module (see #3394172-4: [PP-1] Adopt Drupal core 10.2 config validation infrastructure β†’ ), and found a bug: the call to FormStateInterface::setErrorByName() is wrong.

Root cause: despite the name of that method, it does not accept a form element name (as in #name), but a variation thereof: implode('][', $element['#parents']) (this is clear if you look at \Drupal\Core\Form\FormState::setError()).

Steps to reproduce

Trigger any validation error, and you'll notice that the form validation error is not associated with any form element, only with the entire form:

Proposed resolution

One-line change:

- $form_element_name = $map["$config_name:$property_path"]->elementName;
+ $form_element_name = implode('][', $map["$config_name:$property_path"]->elementParents);

yields:

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

None.

πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
ConfigurationΒ  β†’

Last updated 3 days ago

Created by

πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

Live updates comments and jobs are added and updated live.
  • Usability

    Makes Drupal easier to use. Preferred over UX, D7UX, etc.

  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024