You are here

function googleanalytics_tokens in Google Analytics 7

Same name and namespace in other branches
  1. 7.2 googleanalytics.tokens.inc \googleanalytics_tokens()

Implements hook_tokens().

File

./googleanalytics.tokens.inc, line 31
Builds placeholder replacement tokens for user-related data.

Code

function googleanalytics_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $sanitize = !empty($options['sanitize']);
  $replacements = array();
  if ($type == 'user' && !empty($data['user']->roles)) {
    $account = $data['user'];
    foreach ($tokens as $name => $original) {
      switch ($name) {

        // Basic user account information.
        case 'role-names':
          $names = implode(',', $account->roles);
          $replacements[$original] = $sanitize ? check_plain($names) : $names;
          break;
        case 'role-ids':
          $ids = implode(',', array_keys($account->roles));
          $replacements[$original] = $sanitize ? check_plain($ids) : $ids;
          break;
      }
    }
  }
  return $replacements;
}