While Role Delegation is extremely useful, it doesn't "play well with others." Specifically, Role Delegation overwrites the $form['account']['roles'] array including the form item's title, description and option labels. This means that if you perform a hook_form_alter() with a lower weight or a hook_form_FORM_ID_alter() your changes are lost.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | preserve_form_attributes-1180600-1-D7.patch | 1.21 KB | jyee |
Comments
Comment #1
jyee commentedThis patch preserves the attributes from the $form['account']['roles'] item (or allows role_delegation to create them if they don't exist).
I didn't see the 7.x branch in Git, so this is a simple Diff patch instead of a Git generated patch. It should apply cleanly to 7.x-1.0.
Comment #2
Andrew Schulman commentedThanks for the patch jyee, it looks good. I do want to test it though, to make sure it's doing the right thing in the case where it uses the existing form values instead of assigning new ones. Do you have an example of a module that alters $form['account']['roles'], so I can test against it?
7.x development is in the master branch in Git.
It looks like the same problem happens in 6.x. If you have a patch that would be helpful, otherwise I'll make one.
Andrew.
Comment #3
Andrew Schulman commentedI wrote a quick module to modify $form['account']['roles'], and confirmed that the behavior is as you describe and that the patch fixes it.
Actually, to clarify, Role Delegation wasn't overwriting $form['account']['roles']. Rather, it presents a new form section, $form['account']['roles_change'], which looks and acts the same as $form['account']['roles'] but is presented in different circumstances. The roles_change section didn't incorporate any changes that other modules might have already made to $form['account']['roles'], so the effect to the user was as if Role Delegation had overwritten the changes to the roles section.
I've committed your patch. It will be incorporated into version 7.x-1.1, which will be released shortly. This still needs to be ported to D6.
Comment #4
Andrew Schulman commentedNote that although Role Delegation now picks up changes made to $form['account']['roles'] by modules with lower weight, modules with higher weight that are changing $form['account']['roles'] will have to make the same changes to $form['account']['roles_change'], if they want to play well with Role Delegation. Since their hooks run after Role Delegation's, it can't do anything about that.
Comment #5
Andrew Schulman commentedI think that I won't fix this in D6. It's a minor issue, and to fix it I'd have to change role_delegation_user() to generate complete copies of the user_profile_form or user_register_form forms, including running all of the their hooks, just to be able to pick out a few values from the generated forms. Modifying the values in those forms is fairly rare, so most of the time the effort would be wasted.
Comment #6
Andrew Schulman commentedSo to be clear: This is fixed in D7, won't fix in D6.
Comment #8
francis.patterson commentedSo, I'm working on a Drupal 6 site. I downloaded and installed Util & Module Weights, and tried weighting my custom module and Role Delegation modules several times with positive and negative values, and wrote the following code in an effort to override the #title for the role for an authenticated user:
It works - if you're logged in as an Administrator. If you're logged in as any other role, it defaults back to #title = Role. Any thoughts?
Comment #9
citricguy commentedDid you find a way to work around this?