forked from misd-service-development/drupal-lookup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlookup.tokens.inc
40 lines (34 loc) · 967 Bytes
/
lookup.tokens.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
* @file
* Tokens integration for the Lookup details module.
*/
/**
* Implements hook_token_info_alter().
*/
function lookup_token_info_alter(&$info) {
$info['tokens']['user']['lookup-name'] = array(
'name' => t('Lookup name'),
'description' => t('The user\'s name as set in Lookup.'),
);
}
/**
* Implements hook_tokens().
*/
function lookup_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
$sanitize = !empty($options['sanitize']);
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
case 'lookup-name':
if (isset($account->lookup)) {
$replacements[$original] = $sanitize ? check_plain($account->lookup['name']) : $account->lookup['name'];
}
break;
}
}
}
return $replacements;
}