I am wrtitting one drupal custom module in which i have to create node based on custom values. Here is code which creates node in proper manner.

global $user;
$node = new stdClass();
$node->type = 'my_node_type';
//$node->title  = $nodeInfo->title;
$node->language = LANGUAGE_NONE;
$node->uid = $user->uid;    
$node->field_node_refrence_field['und'][0]['nid'] = $nid-of-reference-field;
$node = node_submit($node); 

BUT, i have auto_nodetitle module enabled for this content type. Due to that, Title is displaying as blank. I have checked module file and found that there is function of "auto_nodetitle_set_title($node)" to set title, but when i used this function in my code nothing happens.

Can anyone give me idea how to save node with auto_nodetitle settings in custom module?

Thank you
Tejas Mehta


atw2525’s picture

Issue summary: View changes

This question was asked years ago but in case anyone else runs into this issue like I did, what worked for me was to call directly auto_nodetitle_set_title($node) and then call node_save($node) to apply the changes. This assumes that any fields the node title is based on have been set by the time auto_nodetitle_set_title($node) is called.