Sync HEAD into 7.x-1.x branch for 1.x release
[project/google_analytics.git] / googleanalytics.tokens.inc
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Builds placeholder replacement tokens for user-related data.
7 */
8
9 /**
10 * Implements hook_token_info().
11 */
12 function googleanalytics_token_info() {
13 $user['roles'] = array(
14 'name' => t('User roles'),
15 'description' => t('The roles the user account is a member of as comma separated list.'),
16 );
17
18 return array(
19 'tokens' => array('user' => $user),
20 );
21 }
22
23 /**
24 * Implements hook_tokens().
25 */
26 function googleanalytics_tokens($type, $tokens, array $data = array(), array $options = array()) {
27 $sanitize = !empty($options['sanitize']);
28
29 $replacements = array();
30
31 if ($type == 'user' && !empty($data['user'])) {
32 $account = $data['user'];
33 foreach ($tokens as $name => $original) {
34 switch ($name) {
35 // Basic user account information.
36 case 'roles':
37 $roles = implode(',', $account->roles);
38 $replacements[$original] = $sanitize ? check_plain($roles) : $roles;
39 break;
40 }
41 }
42 }
43
44 return $replacements;
45 }