- π¦πΊAustralia geoffreyr Sydney, AU / Gadigal country
Given that Drupal 7 has reached its end of life β , this issue should be closed.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.
hook_tokens_alter documentation says "Alter replacement values for placeholder tokens." I would like to alter values for existing core user tokens (I have encrypted core user data that needs to be decrypted). Here is my hook_tokens_alter (taken basically from core "user.tokens.inc"):
/**
* Implements hook_tokens_alter().
*/
function my_module_tokens_alter(&$replacements, $context){
if(isset($context['data']['entity'])) {
$url_options = array('absolute' => TRUE);
if (isset($options['language'])) {
$url_options['language'] = $context['options']['language'];
$language_code = $context['options']['language']->language;
} else {
$language_code = NULL;
}
$sanitize = !empty($context['options']['sanitize']);
if ($context['data']['entity_type'] == 'user' && !empty($context['data']['entity'])) {
$account = $context['data']['entity'];
foreach ($context['tokens'] as $name => $original) {
switch ($name) {
// Basic user account information.
case 'name':
$account->name = my_module_get_decrypted_user_field($account, 'name');
$name = format_username($account);
$replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
case 'mail':
$mail = my_module_get_decrypted_user_field($account, 'mail');
$replacements[$original] = $sanitize ? check_plain($mail) : $mail;
break;
}
}
}
}
}
When I use my module, I get errors like this:
Warning: Illegal offset type in isset or empty in pathauto_cleanstring() (line 180 of /var/www/vhosts/drupal/sites/all/modules/contrib/pathauto/pathauto.inc).
Warning: html_entity_decode() expects parameter 1 to be string, array given in decode_entities() (line 459 of /var/www/vhosts/drupal/includes/unicode.inc).
Warning: Illegal offset type in pathauto_cleanstring() (line 223 of /var/www/vhosts/drupal/sites/all/modules/contrib/pathauto/pathauto.inc).
Notice: Array to string conversion in RulesTokenEvaluator->evaluate() (line 220 of /var/www/vhosts/drupal/sites/all/modules/contrib/rules/modules/system.eval.inc).
Notice: Array to string conversion in RulesTokenEvaluator->evaluate() (line 220 of /var/www/vhosts/drupal/sites/all/modules/contrib/rules/modules/system.eval.inc).
Notice: Array to string conversion in RulesTokenEvaluator->evaluate() (line 220 of /var/www/vhosts/drupal/sites/all/modules/contrib/rules/modules/system.eval.inc).
Notice: Array to string conversion in token_replace() (line 102 of /var/www/vhosts/drupal/includes/token.inc).
Notice: Array to string conversion in token_replace() (line 102 of /var/www/vhosts/drupal/includes/token.inc).
Notice: Array to string conversion in token_replace() (line 102 of /var/www/vhosts/drupal/includes/token.inc).
Notice: Array to string conversion in token_replace() (line 102 of /var/www/vhosts/drupal/includes/token.inc).
Notice: Array to string conversion in token_replace() (line 102 of /var/www/vhosts/drupal/includes/token.inc).
Googling this suggests I cannot actually alter existing token values? E.g.:
https://www.drupal.org/node/1090596 β
https://www.drupal.org/node/1649458 β
Active
7.0 β°οΈ
token system
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Given that Drupal 7 has reached its end of life β , this issue should be closed.
Please upgrade to a supported version and feel free to reopen the issue on the new version if applicable.