Commit 4b821781 authored by hass's avatar hass
Browse files

Renamed [current-user:roles] token to [current-user:role-names] and added [current-user:role-ids].

parent 9c55deca
......@@ -62,7 +62,7 @@ admin/config/system/googleanalytics.
Slot: 1
Name: User roles
Value: [current-user:roles]
Value: [current-user:role-names]
Scope: Visitor
More details about Custom variables can be found in the Google API documentation at
......
......@@ -316,10 +316,10 @@ function googleanalytics_update_7000() {
// Upgrade D6 token placeholder to D7. update_6301 is not required.
$googleanalytics_custom_vars = variable_get('googleanalytics_custom_var', array());
if (!empty($googleanalytics_custom_vars['slots'][1]) && $googleanalytics_custom_vars['slots'][1]['name'] == 'User roles' && $googleanalytics_custom_vars['slots'][1]['value'] = '[roles]') {
$googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:roles]';
if (!empty($googleanalytics_custom_vars['slots'][1]) && $googleanalytics_custom_vars['slots'][1]['name'] == 'User roles' && $googleanalytics_custom_vars['slots'][1]['value'] = '[user-role-names]') {
$googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:role-names]';
variable_set('googleanalytics_custom_var', $googleanalytics_custom_vars);
$messages[] = t("The token placeholder [roles] used in the custom variable 'User roles' has been replaced with [current-user:roles].");
$messages[] = t("The D6 token placeholder [user-role-names] used in the custom variable 'User roles' has been replaced with [current-user:role-names].");
}
return implode(' ', $messages);
......@@ -357,7 +357,7 @@ function googleanalytics_update_7002() {
$googleanalytics_custom_vars['slots'][1]['slot'] = 1;
$googleanalytics_custom_vars['slots'][1]['name'] = 'User roles';
$googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:roles]';
$googleanalytics_custom_vars['slots'][1]['value'] = '[current-user:role-names]';
$googleanalytics_custom_vars['slots'][1]['scope'] = 1; // Sets the scope to visitor-level.
variable_set('googleanalytics_custom_var', $googleanalytics_custom_vars);
......
......@@ -10,9 +10,15 @@
* 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.'),
$user['role-names'] = array(
'name' => t('User role names'),
'description' => t('The role names the user account is a member of as comma separated list.'),
'needs-data' => 'user',
);
$user['role-ids'] = array(
'name' => t('User role ids'),
'description' => t('The role ids the user account is a member of as comma separated list.'),
'needs-data' => 'user',
);
return array(
......@@ -33,9 +39,14 @@ function googleanalytics_tokens($type, $tokens, array $data = array(), array $op
foreach ($tokens as $name => $original) {
switch ($name) {
// Basic user account information.
case 'roles':
$roles = implode(',', $account->roles);
$replacements[$original] = $sanitize ? check_plain($roles) : $roles;
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;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment