Problem/Motivation
When validating fields of type webform_users with validateWebformUsers(), the value is set incorrectly, which causes issues and lost data when saving multiple values with one of them being invalid.
In https://git.drupalcode.org/project/webform/-/blob/6.3.x/src/Element/Webf... the value is set like this:
$element['#value'] = $uids;
$form_state->setValueForElement($element, $uids);
The $form_state->setValueForElement($element, $uids) should be sufficient, whereas the former is not needed at all. In this context $uids is an array of strings, e.g. ['4', '8', '16'], so $element['#value'] = $uids is incorrect, as the value of the field should be an array of user entities.
$form_state->setValueForElement($element, $uids) takes care of that, so there is no need to use the former at all.
Steps to reproduce
See attached video also.
- Go to
/admin/structure/webform/manage/XXX/access. - Add valid user to one of the Users fields, save.
- Add invalid value to the same field, save.
- The invalid value is gone from the field.
- The valid value is turned in to a user ID and is now also considered invalid.
Proposed resolution
Remove $element['#value'] = $uids as redundant. This way, when saving the field with a valid AND an invalid value, the valid value would be kept as a user entity (as it should), and the invalid value would also be shown with the error message included.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| webform-(2).mp4 | 704.88 KB | tuuuukka |
Issue fork webform-3554702
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
tuuuukka commentedComment #6
jrockowitz commentedChange makes perfect sense.