Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've added code which prevents user from submiting 2 roles with the same name.
Comment | File | Size | Author |
---|---|---|---|
#2 | unique.roles.patch_0.txt | 1.57 KB | kuba.zygmunt |
unique.roles.patch.txt | 1.61 KB | kuba.zygmunt |
Comments
Comment #1
breyten CreditAttribution: breyten commented+1 on feature (I think it's always useful to have these kind of checks -- will probably save us bug reports in the future;), but -1 on the patch. It's not necessary to call db_fetch_object to just get a role id. You can change it to this:
$rid = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s'", $edit['name']);
and then simply
if ($rid) {
.
.
.
Comment #2
kuba.zygmunt CreditAttribution: kuba.zygmunt commentedOk, I've changed code. I hope that this code will be good enough. ;)
Comment #3
Uwe Hermann CreditAttribution: Uwe Hermann commented+1. Patch applies and works as expected.
Comment #4
Dries CreditAttribution: Dries commentedAny reason you can't use the same code twice? I like the first approach better; avoids an object being created.
Comment #5
Dries CreditAttribution: Dries commentedComment #6
Jaza CreditAttribution: Jaza commentedPatch no longer needed: uniqueness of role names is enforced in HEAD in the user_admin_role_validate() function.