[support] Creating Content Node Programmatically and Returning to Tab After Node is Saved, Wherever it was Called From

Moses Elias (2) iom at netvision.net.il
Mon Apr 19 11:49:10 UTC 2010


I've created a new content type. The content type includes CCK fields. 
Now I want to call it by creating a node and saving it from a tab on 
certain pages. I want to do this from within a module.

The module uses a MENU_LOCAL_TASK as well as a page_callback that's 
attached to a function to be called from specific locations on the site. 
When I click the tab I want to the content type to render, then add my 
information to the node and save it, but after saving to return to my 
original location.

I tried using drupal_goto in the callback. That works fine and it takes 
me to my node, but it doesn't return me to my original location after 
the node data is saved. So if I can't return to my original tab, that 
option is not unsuitable.

The other alternative is to use the following sequence of function calls 
in the page callback function in the following order:

drupal_retrieve_form();
drupal_prepare_form();
and lastly drupal_render_form();

At this stage the node form is partially rendering but not all the 
fields are being displayed.

I'm not even certain this is the correct way to programmatically add a 
node. Can anybody advise about best practices for programmatically 
adding a node through a drupal module?

(I've even increased the module weight by defining it in the install file.)

Thanks!









More information about the support mailing list