when working with multiple content types that are related to each other, i've needed to obtain the new node id. i had to do this with a separate call to the database, so, to improve the node_factory_save_node function, i've made a slight modification to return the new node value, or false if it wasn't created.

i've also patched the < at the start of the file :)

CommentFileSizeAuthor
node_factory.module.patch1.1 KBGeorge2

Comments

clemens.tolboom’s picture

Version: 5.x-2.x-dev » 5.x-1.x-dev

Great suggestion.

I applied part of the patch.
- returning nid when saved.
- returning nothing when not saved. Hope this makes more robust code.

$nid= node_factory_save_node( $edit);
if( isset( $nid)){
  // do more
}

Regards,
Clemens

clemens.tolboom’s picture

Assigned: Unassigned » clemens.tolboom
Status: Active » Fixed
George2’s picture

to be anal, i think the save_node should return false if it wasn't successful ;)

to assign the output of a function to a variable, then test if that variable was really set, just, doesn't feel right!

if (($nid = node_factory_save_node($edit)) != false){
// ... good stuff
}
else{
// ... not successful
}

to be really anal, it should return true if the node save was successful imo, but that would prove a problem with retrieving the id, so this is a good middle ground?

of course, if this was oop, it'd be a lot easier - $edit->getNodeId() ;)

clemens.tolboom’s picture

Status: Fixed » Closed (fixed)

return value is now FALSE