Thanks for producing role_weights, it provides a key tool in improving the "rolability" of Drupal.

A small request. I find it awkward that a structured array is returned by role_weights_get_highest(). I always want just the rid, and so have to include extra code to get at it. If we want to get the role name, that is always readily available through $user->roles or user_roles().

I'd be happy to submit a patch making this change.

CommentFileSizeAuthor
#4 return_rid_only.patch.txt1.02 KBpfaocle

Comments

pfaocle’s picture

Hmm, that sounds OK to me. There was a similar discussion here about the return value. I think I agree - returning the role rid should be enough. Budda is using the module - any thoughts?

(nedjo - your input is much appreciated! I'm stuck in Windows until my new router arrives (Speedtouch modems, ArchLinux and CHAP anyone?), so will review/test your patches as soon as I can! Please feel free to roll a patch for this one too! Cheers!)

budda’s picture

Just a rid is what I originally expected, but having the text name available without having to do an additional query was handy.

I used it in the path_access module, and specifically made use of the role name returned, but looking back at the code briefly I'm not sure why i didn't just use the rid returned?!

I've not got time to change and test my module at the moment to work with just rid value.

Is there any benefit to just returning the rid from the function? ...apart from being able to use it inline for function calls/logic.

pfaocle’s picture

Assigned: nedjo » pfaocle
Status: Active » Needs review

The only other thing I can think of was in my original use of the module - in a theme in which I needed the role name specifically. If we lost the role name returned here, then the theme function would have to do a bit more work with $user->roles or user_roles().

Not a major reason not to drop the role name returned, just a thought. Here's a patch against current cvs for further review anyway.

pfaocle’s picture

StatusFileSize
new1.02 KB

... and the patch.

pfaocle’s picture

Status: Needs review » Fixed

Applied to HEAD: role_weights_get_highest() will now return simply a role rid.

Please update your code/modules as neccessary if you can help out testing the HEAD version. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)