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

pfaocle’s picture

Great idea, have been playing with tokens and e-commerce - will take a look!

pfaocle’s picture

Title: Provide tokens for the highest/lowest weight role » Provide tokens for the highest weighted role
Version: master » 5.x-1.x-dev
Assigned: Unassigned » pfaocle
Status: Active » Needs review
StatusFileSize
new1.05 KB

Here's a patch for 5.x.

No "lowest" one yet, but then the module doesn't do that yet.

pfaocle’s picture

Component: Code » External module integration
StatusFileSize
new2.78 KB

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'. The role_weights_get_highest function 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_highest could possibly be deprecated and removed in a later version.

I've very briefly tested this:

  global $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.

greggles’s picture

Status: Needs review » Needs work

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.

pfaocle’s picture

Status: Needs work » Needs review
StatusFileSize
new2.8 KB

Sure.

pfaocle’s picture

Status: Needs review » Needs work

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.

pfaocle’s picture

Status: Needs work » Needs review
StatusFileSize
new1.44 KB

This patch will apply to current 5,x-1.x-dev and HEAD branches, but NOT to 1.2.

pfaocle’s picture

Status: Needs review » Fixed

Committed to 5.x-1.x-dev and HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.