Closed (fixed)
Project:
Role Weights
Version:
master
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
1 Jun 2006 at 01:01 UTC
Updated:
28 Jun 2006 at 12:54 UTC
Jump to comment: Most recent file
When feeding my user's $user->roles array (array(1) { [2]=> string(18) "authenticated user" }) into $role = module_invoke('role', 'weights_get_highest', $user->roles); it's returning two elements in the array:-
array(2) { [0]=> int(2) [1]=> string(18) "authenticated user" }
From the description I assumed the function would only return the single highest role id & role name/description. Currently this kinda breaks the use of this module I think?
Any idea what the [0] => 2 is? I tried both the current CVS and 4.7.0 versions of the module. Both gave the same response.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | roleweights_gethighest_returnsinglearrayelement_r1.patch.txt | 872 bytes | pfaocle |
| #2 | roleweights_gethighest_returnsinglearrayelement.patch.txt | 653 bytes | pfaocle |
Comments
Comment #1
pfaocleIt does: the first element of the array is the 'highest' role id (2) and the second the 'highest' role name. There may have been a reason for returning it like this, or perhaps not... I'll take a look. Ideally, I suppose what we want is:
array (2 => 'authenticated user')returned. Cheers!
Comment #2
pfaocleLike this.
Comment #3
pfaocleLets return an empty array too, if no matching role is found.
The only place I've currently been calling this is in a theme's template.php file, when theming usernames:
which with this patch now becomes:
using array_shift to obtain the first array elements value. Is there a similar method to obtain the first key when the role id is required and not the role name? Is this a preferable return value for you, budda?
Comment #4
buddaAhh, so that's what the first element is for. A bit obscure format :)
array (2 => 'authenticated user')is just like I was expecting. Woo. Thanks! Is this in CVS?Comment #5
buddaHmm, i see what you mean by the array_shift() stuff for the key.
Maybe an indexed array would work better, like:
Or return the result as an stdclass object?
Comment #6
pfaocleNo, I've not applied the patch yet, mainly for the finickity concerns about the return format. I think an associative array is the way forward - will take a look possibly tomorrow. I'm in the middle of moving house at the moment: hectic-tastic.
Thanks for the feedback.
Comment #7
pfaocleFixed - applied to HEAD and 4.7 branch:
Cheers!
Comment #8
(not verified) commentedComment #9
pfaoclebudda: http://drupal.org/node/70772 -> another suggestion for the return value from role_weights_get_highest() from nedjo. Any thoughts?