Token support

marcus178 - October 13, 2009 - 20:46
Project:Birthdays
Version:6.x-1.0-rc1
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I think it would be nice if some token support was added to this modules for things such age. I've managed to do it adding the following but it may be something to consider adding.

/**
* Implementation of hook_token_values(). (token.module)
*/
function birthdays_token_values($type, $object = NULL) {
  $values = array();
  switch ($type) {
    case 'user':
      if (isset($object)) {
        $account = $object;
      }
      else {
        global $user;
        $account = user_load(array('uid' => $user->uid));
      }

      $values['birthday_age'] = $account->age;

      break;
  }
  return $values;
}

/**
* Implementation of hook_token_list(). (token.module)
*/
function birthdays_token_list($type = 'all') {
  if ($type == 'user' || $type == 'all') {
    $tokens['user']['birthday_age']  = t("User's age");

    return $tokens;
  }
}

 
 

Drupal is a registered trademark of Dries Buytaert.