Projet

Général

Profil

Paste
Télécharger (1,41 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / matomo / matomo.tokens.inc @ 60283730

1
<?php
2

    
3
/**
4
 * @file
5
 * Builds placeholder replacement tokens for user-related data.
6
 */
7

    
8
/**
9
 * Implements hook_token_info().
10
 */
11
function matomo_token_info() {
12
  $user['matomo-role-names'] = array(
13
    'name' => t('User role names'),
14
    'description' => t('The role names the user account is a member of as comma separated list.'),
15
    'needs-data' => 'user',
16
  );
17
  $user['matomo-role-ids'] = array(
18
    'name' => t('User role ids'),
19
    'description' => t('The role ids the user account is a member of as comma separated list.'),
20
    'needs-data' => 'user',
21
  );
22

    
23
  return array(
24
    'tokens' => array('user' => $user),
25
  );
26
}
27

    
28
/**
29
 * Implements hook_tokens().
30
 */
31
function matomo_tokens($type, $tokens, array $data = array(), array $options = array()) {
32
  $sanitize = !empty($options['sanitize']);
33
  $replacements = array();
34

    
35
  if ($type == 'user' && !empty($data['user']->roles)) {
36
    $account = $data['user'];
37

    
38
    foreach ($tokens as $name => $original) {
39
      switch ($name) {
40
        // Basic user account information.
41
        case 'matomo-role-names':
42
          $names = implode(',', $account->roles);
43
          $replacements[$original] = $sanitize ? check_plain($names) : $names;
44
          break;
45

    
46
        case 'matomo-role-ids':
47
          $ids = implode(',', array_keys($account->roles));
48
          $replacements[$original] = $sanitize ? check_plain($ids) : $ids;
49
          break;
50
      }
51
    }
52
  }
53

    
54
  return $replacements;
55
}