Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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 CreditAttribution: 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
apadernoWhy is the code loading the user object, when it is already passed to the function?
Comment #3
MGN CreditAttribution: 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