Closed (fixed)
Project:
Administer Users by Role
Version:
8.x-3.3
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Feb 2023 at 09:02 UTC
Updated:
3 Jul 2023 at 08:25 UTC
Jump to comment: Most recent, Most recent file
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.