Download & Extend

On first node save $node->name is not set

Project:Drupal core
Version:7.7
Component:token system
Category:bug report
Priority:minor
Assigned:Unassigned
Status:closed (duplicate)

Issue Summary

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:

<?php
case 'author':
         
$name = ($node->uid == 0) ? variable_get('anonymous', t('Anonymous')) : $node->name;
         
$replacements[$original] = $sanitize ? filter_xss($name) : $name;
          break;
?>

to:
<?php
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

#1

#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().

#2

Status:active» closed (duplicate)

Thanks for your report. This is a duplicate of #1185842: The [node:author] token does not use format_username().

nobody click here