Alternative to drupal_goto Within a page callback, I need to:


Create a new node.
Retrieve the nid from that new node.
Create an entity reference in an already existing node (referenced in a parameter passed to my page callback) TO that newly created node.


The first thought was to use drupal_goto. However; drupal_goto "ends the request".


  (per
  http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_goto/7)


As expected, I execute the drupal_goto('node/add/newnode'); The node gets created, and I'm out of the page callback... 

Any suggestions would be most welcome!
Perhaps something like this:

function mymodule_page_callback($parent_nid){

  global $user;
  try{
    // Create new node, assumes default LANGUAGE_NONE
    $node = new stdClass();
    $node-&gt;title = 'Title';
    $node-&gt;type = 'my_type';
    $node-&gt;language = LANGUAGE_NONE;
    $node-&gt;uid = $user-&gt;uid; 
    $node-&gt;status = 1; 
    node_object_prepare($node); // Sets some defaults.
    $node = node_submit($node); // Prepare node for saving
    node_save($node); // Returns $node by reference with nid

    // Set entity reference on parent node
    $parent = node_load($parent_nid);
    $parent-&gt;field_entity_reference[LANGUAGE_NONE][] = array(
      'target_id' =&gt; $node-&gt;nid
    );
    // Save parent
    node_save($parent);
    // Go to edit form for new child node
    drupal_set_message("Node created");
    drupal_goto('node/'.$node-&gt;nid.'/edit');
  }catch(Exception $e){
    watchdog_exception('my_module', $e);
    drupal_set_message("A problem occured creating the node", 'error');
    drupal_goto(); // front page
  }

}