Download & Extend

Provide tokens for the highest weighted role

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

Title:Provide tokens for the highest/lowest weight role» Provide tokens for the highest weighted role
Version:master» 5.x-1.x-dev
Assigned to:Anonymous» leafish_paul
Status:active» needs review

Here's a patch for 5.x.

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

AttachmentSize
role_weights_1065002-1.patch 1.05 KB

#3

Component:Code» External module integration

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:

<?php
 
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.

AttachmentSize
role_weights_tokens_318777-2.patch 2.78 KB

#4

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.

#5

Status:needs work» needs review

Sure.

AttachmentSize
role_weights_tokens_318777-3.patch 2.8 KB

#6

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.

#7

Status:needs work» needs review

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

AttachmentSize
role_weights_token_318777-4.patch 1.44 KB

#8

Status:needs review» fixed

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

#9

Status:fixed» closed (fixed)

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

nobody click here