Logged in as a sub-admin. After unchecking a role on the user edit form and submitting the form, the role is still assigned to the user.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | administerusersbyrole.role-removal.3343114-11.patch | 1.01 KB | siemen_hermans |
| #8 | 3343114-form-submit-fix.patch | 920 bytes | a.kovrigin |
| #4 | administerusersbyrole.role-removal.3343114-4.patch | 785 bytes | adamps |
| #3 | 3343114-after-patch.png | 24.88 KB | arun velusamy |
| #3 | 3343114-before-patch.png | 24.86 KB | arun velusamy |
Comments
Comment #2
adr_p commentedAttaching a patch.
Comment #3
arun velusamy commentedI have verified the patch #2 and tested it on Drupal version 9.5.x. The patch works fine and I have added the before and after screenshots for reference.
Comment #4
adamps commentedThanks for the report. The patch doesn't apply however it showed a good direction. I tested and changed it slightly to work in all cases I could think of.
We've had a series of bugs many of them caused by bad fixes to previous bugs:
It would if someone could write a test for roles, including as many of the above cases as possible.
Comment #5
sagesolutions commentedI successfully applied patch #4 and can now remove (and add) roles when editing users.
I agree that tests should be added to prevent regression issues
Comment #7
adamps commentedThanks. I've committed the fix and raised #3354395: Add tests for roles.
Comment #8
a.kovrigin commentedIt can be a situation, when there is no roles key in $form['account'] array on form submission which causes the fatal error.
The patch fixes the issue.
Comment #9
adamps commentedHow would that be? The roles field is always set in AccountForm. If a module wishes to remove the field from display they should use the '#access'. Removing the array key entirely could cause bugs in other modules too.
This issue has already been fixed, and I've made a release, so I can't make a new commit here without causing confusion. As far as I can see, the same problem was true before this fix. So please raise a new issue if you wish to continue the discussion.
Comment #11
siemen_hermans commentedThe changes introduced by this fix can lead to a TypeError in the array_diff function.
In our specific situation the user can only have 1 role. As a result
$form['account']['roles']['#default_value']returns a string.This causes a TypeError in the array_diff function.
A simple check of the value returned by
$form['account']['roles']['#default_value']could resolve the issue.