summaryrefslogtreecommitdiffstats
path: root/googleanalytics.tokens.inc
blob: 51be115163eb6ad21538168c415f00c7baefc396 (plain)
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
41
42
43
44
45
<?php
// $Id$

/**
 * @file
 * Builds placeholder replacement tokens for user-related data.
 */

/**
 * Implements hook_token_info().
 */
function googleanalytics_token_info() {
  $user['roles'] = array(
    'name' => t('User roles'),
    'description' => t('The roles the user account is a member of as comma separated list.'),
  );

  return array(
    'tokens' => array('user' => $user),
  );
}

/**
 * Implements hook_tokens().
 */
function googleanalytics_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);

  $replacements = array();

  if ($type == 'user' && !empty($data['user'])) {
    $account = $data['user'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        // Basic user account information.
        case 'roles':
          $roles = implode(',', $account->roles);
          $replacements[$original] = $sanitize ? check_plain($roles) : $roles;
          break;
      }
    }
  }

  return $replacements;
}