function piwik_tokens in Piwik Web Analytics 8
Same name and namespace in other branches
- 7.2 piwik.tokens.inc \piwik_tokens()
Implements hook_tokens().
File
- ./
piwik.tokens.inc, line 34 - Builds placeholder replacement tokens for user-related data.
Code
function piwik_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$sanitize = !empty($options['sanitize']);
$replacements = [];
if ($type == 'user' && !empty($data['user'])) {
$account = $data['user'];
foreach ($tokens as $name => $original) {
switch ($name) {
// Basic user account information.
case 'piwik-role-names':
$names = implode(',', $account
->getRoles());
$replacements[$original] = $sanitize ? Html::escape($names) : $names;
$bubbleable_metadata
->addCacheableDependency($account);
break;
case 'piwik-role-ids':
$ids = implode(',', array_keys($account
->getRoles()));
$replacements[$original] = $sanitize ? Html::escape($ids) : $ids;
$bubbleable_metadata
->addCacheableDependency($account);
break;
}
}
}
return $replacements;
}