Closed (fixed)
Project:
Token
Version:
6.x-1.12
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
25 Oct 2009 at 09:34 UTC
Updated:
21 Mar 2010 at 03:30 UTC
I try to use token starter. I have done my own module by copying the 2 files .info and .module.
I succesfully my new modules.
But I can't see my new tokens in pathauto. any help are welcome:
I'm a newbie in php...
/**
* Implementation of hook_token_list().
*/
function tokenSTARTER_token_list($type = 'all') {
if ($type == 'user' || $type == 'all') {
$tokens['global']['highest-role'] = t('Highest role from current user.');
}
return $tokens;
}
/**
* Implementation of hook_token_values().
*/
function tokenSTARTER_token_values($type, $object = NULL) {
$values = array();
switch ($type) {
case 'user' :
global $user;
$values['highest-role'] = role_weights_get_highest($user->roles);
break;
}
return $values;
}
Comments
Comment #1
heyyo commentedI finally found a solution to create token from user roles. Advices are really welcome, if my code needs modification for performance or security.
My users have only one role : painter or sculptor or photographer or designer (except authenticated users or anonymous)
Comment #2
avpadernoWhy is the code loading the user object, when it is already passed to the function?
Comment #3
MGN commentedThe reason for loading the user object is that $object defaults to NULL. You might want to do the following instead...
You could also economize on the in_array() calls. Perhaps something like....
Comment #4
dave reid