function cas_tokens in CAS 7
Same name and namespace in other branches
- 8 cas.tokens.inc \cas_tokens()
- 2.x cas.tokens.inc \cas_tokens()
Implements hook_tokens().
File
- ./
cas.tokens.inc, line 43 - Token module integration.
Code
function cas_tokens($type, $tokens, array $data = array(), array $options = array()) {
$sanitize = !empty($options['sanitize']);
$replacements = array();
if ($type == 'cas' && !empty($data['cas'])) {
$cas = $data['cas'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'name':
$replacements[$original] = $sanitize ? check_plain($cas) : $cas;
break;
}
}
}
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'cas':
// Provide [user:cas] token.
if (!empty($account->cas_name)) {
$replacements[$original] = $sanitize ? check_plain($account->cas_name) : $account->cas_name;
}
break;
}
}
// Provide [user:cas:?] dynamic tokens.
if ($cas_tokens = token_find_with_prefix($tokens, 'cas')) {
$replacements += token_generate('cas', $cas_tokens, array(
'cas' => $account->cas_name,
), $options);
}
}
return $replacements;
}