Posted by greggles on October 8, 2008 at 10:48pm
| Project: | Role Weights |
| Version: | 5.x-1.x-dev |
| Component: | External module integration |
| Category: | task |
| Priority: | normal |
| Assigned: | leafish_paul |
| Status: | closed (fixed) |
Issue Summary
See http://drupal.org/node/162502 for some of the motivation. I plan to add "role" to token, but it would be much better implemeted by role weights since token doesn't have a concept of higher/lower weights.
Comments
#1
Great idea, have been playing with tokens and e-commerce - will take a look!
#2
Here's a patch for 5.x.
No "lowest" one yet, but then the module doesn't do that yet.
#3
Bigger one. This one provides "lowest" role tokens.
I've also added function
role_weights_get_weighted_max($roles, $weight_end), where $weight_end should be 'lightest' or 'heaviest'. Therole_weights_get_highestfunction remains so as to not break too much in 5.x.However, I didn't add a wrapper type function for ..._get_lowest(), as 'lowest' and 'highest' don't really make sense (as mentioned here). I'm tempted to go with the obvious "lightest" for most negative and "heaviest" for most positive, seeing as though we're dealing with weights (good headsmack moment from me on that one earlier!).
role_weights_get_highestcould possibly be deprecated and removed in a later version.I've very briefly tested this:
<?phpglobal $user;
$string = 'I am [user] with lightest role [lightest-role-id]:[lightest-role]';
print token_replace($string, 'user', $user);
$string = 'I am [user] with heaviest role [heaviest-role-id]:[heaviest-role]';
print token_replace($string, 'user', $user);
?>
Feedback/testing appreciated.
#4
Awesome! Thanks for your work on this.
One thing: it's probably best to run the role names through check_plain() just to be sure.
#5
Sure.
#6
Added in the better named API function (role_weights_get_weighted_max with a parameter) and left ..._get_highest() in as a wrapper function to be deprecated/removed. Committed to 5.x/HEAD today.
Just need to re-roll this with the two Token functions now.
#7
This patch will apply to current 5,x-1.x-dev and HEAD branches, but NOT to 1.2.
#8
Committed to 5.x-1.x-dev and HEAD.
#9
Automatically closed -- issue fixed for 2 weeks with no activity.