I'm trying to create a custom token. I've already successfully implemented hook_token_info
, and the token shows up. However, whenever I insert a the token [site:chosen-school-year]
wherever I'm able, it doesn't show up.
Here's the code to implement the token:
function capstone_tokens_tokens($type, $tokens, array $data = array(), array $options = array()){
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type = 'site'){
foreach ($tokens as $name => $original) {
switch($name){
case 'chosen-school-year':
$replacements[$original] = getSelectedSchoolYear();
break;
}
}
}
return $replacements;
}
getSelectedSchoolYear()
is a function that I use in a different location that works as it's meant to.
I've compared my code to the samples provided here and here, and haven't found any clear discrepancies between my code and theirs. I have tried clearing the Drupal cache, but that didn't provide any results. Is there something else in the system that I should be checking/trying?
$type
is used, from my understanding, to help identify the tokens, for organization.getSelectedSchoolYear()
runs a database query - would it help if I edited the question to include that code?