Provide tokens for the highest weighted role

greggles - October 8, 2008 - 22:48
Project:Role Weights
Version:5.x-1.x-dev
Component:External module integration
Category:task
Priority:normal
Assigned:leafish_paul
Status:closed
Description

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.

#1

leafish_paul - October 17, 2008 - 22:47

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

#2

leafish_paul - October 18, 2008 - 00:47
Title:Provide tokens for the highest/lowest weight role» Provide tokens for the highest weighted role
Version:HEAD» 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

leafish_paul - October 18, 2008 - 01:29
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

greggles - October 18, 2008 - 01:50
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

leafish_paul - October 18, 2008 - 02:00
Status:needs work» needs review

Sure.

AttachmentSize
role_weights_tokens_318777-3.patch 2.8 KB

#6

leafish_paul - January 28, 2009 - 13:18
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

leafish_paul - January 28, 2009 - 13:25
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

leafish_paul - January 28, 2009 - 17:06
Status:needs review» fixed

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

#9

System Message - February 11, 2009 - 17:10
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.