I have defined few tokens that are grouped in few separate groups similar to [node:content-type:name]
scheme. For example I'd like to have a token like [master:sub_group_1:tokan_A]
. So This is how hook_token_info()
looks like:
function MY_MODULE_token_info() {
$tokens = array();
$types = array();
$types['master'] = array(
'name' => 'Master group',
'description' => 'This is the master group',
);
$types['sub_group_1'] = array(
'name' => 'Sub group 1',
'description' => 'This is the first sub group',
// this tells this group that it's parent is 'master' group.
'needs-data' => 'master',
);
$tokens['sub_group_1']['token_A'] = array(
'name' => 'Token A',
'description' => 'This token prints letter A',
);
return array(
'types' => $types,
'tokens' => $tokens,
);
}
I'll skip MY_MODULE_tokens()
as it's irrelevant here, but token_replace()
works perfectly. It replaces [master:sub_group_1:token_A]
correctly. But the problem is that token
module does not list my custom tokens in available tokens section and when I try to use [master:sub_group_1:token_A]
in forms that get validated by token
module, I get The %element-title is using the following invalid tokens
error message.
What is the correct method to define custom tokens and group them to avoid conflicts with tokens defined by other modules?