0

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?

2
  • what is [$type = 'site'] ? Content type? I don't think you can use content type at that level - it should be $type = 'node' - which is the type of the entity you are trying to extract data from
    – oksana-c
    Commented Jan 21, 2016 at 0:37
  • The $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?
    – Greenstack
    Commented Jan 21, 2016 at 19:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.