uc_roles_tokens

  1. drupal
    1. 7 uc_roles.tokens.inc function
Drupal 7 uc_roles_tokens($type, $tokens, $data = array(), $options = array())

Implements hook_tokens().

File

sites/all/modules/ubercart/uc_roles/uc_roles.tokens.inc, line 37
Token hooks for the uc_roles module.

Code

function uc_roles_tokens($type, $tokens, $data = array(), $options = array()) {
  $language_code = NULL;
  if (isset($options['language'])) {
    $language_code = $options['language']->language;
  }
  $sanitize = !empty($options['sanitize']);

  $replacements = array();

  if ($type == 'uc_role' && !empty($data['uc_role'])) {
    $object = $data['uc_role'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'expiration':
          $replacements[$original] = format_date($object->expiration, 'medium');
          break;
        case 'name':
          $replacements[$original] = $sanitize ? check_plain(_uc_roles_get_name($object->rid)) : _uc_roles_get_name($object->rid);
          break;
      }
    }

    if ($expiration_tokens = token_find_with_prefix($tokens, 'expiration')) {
      $replacements += token_generate('date', $expiration_tokens, array('date' => $object->expiration), $options);
    }
  }

  return $replacements;
}