Right, for example:<br><br>
$node = new stdClass();<br>
$node->title = 'foo';<br>
$node->uid = 1;<br>$node->name = admin;<br><br>... (lot of other stuff)<br><br>$node = node_submit($node);<br>node_save($node);<br>
<br>If you look at <a href="http://api.drupal.org/api/function/node_submit/5">http://api.drupal.org/api/function/node_submit/5</a> you will see that the parameter is not a reference and that the function returns the node object.<br>
<br>Victor Kane<br><a href="http://awebfactory.com.ar">http://awebfactory.com.ar</a><br><br><br><div class="gmail_quote">On Wed, Mar 12, 2008 at 1:37 AM, Nancy Wichmann <<a href="mailto:nan_wich@bellsouth.net">nan_wich@bellsouth.net</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I had a 5.x module where I was creating a node and it wouldn't even save the uid unless I also set the username.<br>
<br>
Nancy E. Wichmann, PMP<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
-----Original Message-----<br>
From: <a href="mailto:development-bounces@drupal.org">development-bounces@drupal.org</a> [mailto:<a href="mailto:development-bounces@drupal.org">development-bounces@drupal.org</a>]On Behalf Of Omar Abdel-Wahab<br>
Sent: Tuesday, March 11, 2008 11:30 PM<br>
To: <a href="mailto:development@drupal.org">development@drupal.org</a><br>
Subject: Re: [development] programmatic creation of node<br>
<br>
Any ideas why does this fails to set the node author:<br>
$node = new stdClass();<br>
$node->title = 'foo';<br>
$node->uid = 1;<br>
node_submit($node);<br>
node_save($node);<br>
<br>
While this succeeds:<br>
$node = new stdClass();<br>
$node->title = 'foo';<br>
node_submit($node);<br>
$node->uid = 1;<br>
node_save($node);<br>
<br>
<br>
On Mon, Mar 10, 2008 at 9:17 PM, Earnie Boyd<br>
<<a href="mailto:earnie@users.sourceforge.net">earnie@users.sourceforge.net</a>> wrote:<br>
> Quoting Victor Kane <<a href="mailto:victorkane@gmail.com">victorkane@gmail.com</a>>:<br>
><br>
> > On Mon, Mar 10, 2008 at 10:16 AM, Earnie Boyd <<a href="mailto:earnie@users.sourceforge.net">earnie@users.sourceforge.net</a>><br>
> > wrote:<br>
> ><br>
> >> Quoting Victor Kane <<a href="mailto:victorkane@gmail.com">victorkane@gmail.com</a>>:<br>
> >><br>
> >> > I do this a lot, so I will ad my two cents.<br>
> >> ><br>
> >> > The following line is absolutely essential for "good housekeeping",<br>
> >> > especially if you are using cck fields:<br>
> >> ><br>
> >> > $node = node_submit($node);<br>
> >> ><br>
> >> > However, it will NOT work if ... it shouldn't; for example if you omit<br>
> >> (as<br>
> >> > does the above code) initializing the uid attribute.<br>
> >> ><br>
> >><br>
> >> Which is what <a href="http://api.drupal.org/api/function/node_object_prepare" target="_blank">http://api.drupal.org/api/function/node_object_prepare</a><br>
> >> does when nid is not set in the node object.<br>
> ><br>
> ><br>
> > OK, great. But I thought I read KarenS stating somewhere that the<br>
> > node_submit($node) was good when we are dealing with CCK fields... would be<br>
> > good to know<br>
> ><br>
><br>
> Maybe because CCK uses the nodeapi ``presave'' operation which<br>
> node_save calls first.<br>
><br>
> <code<br>
> source="<a href="http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/cck/content.module?view=markup" target="_blank">http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/cck/content.module?view=markup</a>><br>
> /**<br>
> * Nodeapi 'presave' op.<br>
> *<br>
> */<br>
> function content_presave(&$node) {<br>
> _content_field_invoke('presave', $node);<br>
> _content_field_invoke_default('presave', $node);<br>
> }<br>
> </code><br>
><br>
><br>
><br>
><br>
> Earnie -- <a href="http://for-my-kids.com/" target="_blank">http://for-my-kids.com/</a><br>
> -- <a href="http://give-me-an-offer.com/" target="_blank">http://give-me-an-offer.com/</a><br>
><br>
><br>
<br>
<br>
<br>
--<br>
Omar Abdel-Wahab<br>
<br>
</div></div></blockquote></div><br>