I have a few custom tokens to create which are based off of node context. At first I thought I could have them as their own top level group with code like this:
$info['types']['mpep_policy'] = [
'name' => t('MPEP Policy'),
'description' => t('mpep policy tokens'),
'needs-data' => 'node',
];
$mpep_customs = ['Liability:Each Occurence', 'Liability:General Aggregate', 'Business Description', 'IM Premium', 'Policy Documents'];
foreach ($mpep_customs as $mpep_custom) {
$info['tokens']['mpep_policy'][$mpep_custom] = [
'name' => $mpep_custom,
];
}
This gives me the ideal situation of having "MPEP Policy" show as a top level token group; but, when creating token values there is no node context available. I read a tutorial suggesting that setting 'needs-data' to node would do this but it does not. I suspect this is from the module which is using token replacements (FillPDF). It verifies that I am passing in entities that match the type of token being used.
So I think the best UI for the token browser that I can expect to work is to have a subgroup called MPEP Policy listed under Nodes:
Nodes
- MPEP Policy
-- Liability:Each Occurence
-- Liability:General Aggregate
This code seemed like it should be sufficient for that:
$mpep_customs = ['Liability:Each Occurence', 'Liability:General Aggregate', 'Business Description', 'IM Premium', 'Policy Documents'];
foreach ($mpep_customs as $mpep_custom) {
$info['tokens']['node']['mpep_policy'][$mpep_custom] = [
'name' => $mpep_custom,
];
}
but this only gives me a blank label under Nodes (with no description) and the token [node:mpep_policy]. But it is not expandable to show my custom tokens.
What am I missing here?