Profile tokens are not replaced

Created on 10 March 2011, over 13 years ago
Updated 31 August 2024, 3 months ago

When adding a link field to user profiles and using user tokens (e.g. [user:name]) to the link title, the tokens are not replaced.

I was able to get the tokens replaced by replacing:

$item['url'] = token_replace($item['url'], array('node' => $token_node));

With:

$token_user = !isset($node->nid) && isset($node->uid) ? user_load($node->uid) : NULL;
$item['url'] = token_replace($item['url'], array('node' => $token_node, 'user' => $token_user));

And replacing:

$title = filter_xss(token_replace($title, array('node' => $token_node)),
    array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));

With:

$token_user = !isset($node->nid) && isset($node->uid) ? user_load($node->uid) : NULL;
$title = filter_xss(token_replace($title, array('node' => $token_node, 'user' => $token_user)),
    array('b', 'br', 'code', 'em', 'i', 'img', 'span', 'strong', 'sub', 'sup', 'tt', 'u'));

Hopefully I am using the correct way to detect if you are viewing a node or a profile.

🐛 Bug report
Status

Closed: outdated

Component

Code

Created by

🇳🇱Netherlands j.stuyts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    I'll close this issue due to inactivity for 12 years and upcoming EOL of Drupal 7 in January 2025. While the project version for Drupal 7 will keep providing support for security issues and website breaking bug fixes for Drupal 7, we should try to minimize the open issues for Drupal 7 in the queue as much as possible. Thanks for the report and all the efforts in here. Feel free to re-open if you can provide a fix or found an additional related problem which increases the issue priority to "Critical" here.

Production build 0.71.5 2024