Closed (duplicate)
Project:
Drupal core
Version:
7.7
Component:
token system
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
31 Aug 2011 at 15:50 UTC
Updated:
31 Aug 2011 at 15:59 UTC
When creating a new node and using auto_nodetitle we get an error that $node->name is undefined.
we need to set this value before we try to use it. Simple short term fix around line 160 of modules/node/node.tokens.inc)
change:
case 'author':
$name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
break;
to:
case 'author':
if(!isset($node->name)) { $node->name = db_query("SELECT name FROM {users} WHERE uid = :d", array(':d' => $node->uid))->fetchField(); }
$name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
break;
Comments
Comment #1
chrisjlock commented#1185842: The [node:author] token does not use format_username()
case 'author':
- $name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
- $replacements[$original] = $sanitize ? filter_xss($name) : $name;
+ $account = user_load($node->uid);
+ $name = format_username($account);
+ $replacements[$original] = $sanitize ? check_plain($name) : $name;
break;
This would also fix this issue, by loading the name using user_load().
Comment #2
damien tournoud commentedThanks for your report. This is a duplicate of #1185842: The [node:author] token does not use format_username().