Problem with node_api insert callback

neural - May 16, 2007 - 16:31
Project:API
Version:HEAD
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

Hi,

I'm working on a little module which opens a forum topic for each story you create. The story shows a link to the forum topic in place of the comments system and the forum topic shows the teaser of the story and a link back to this story.

The idea is to bring integration between articles and forums and having a specific forum which contains all the news discussion.

I'm trying to use Drupal's nodeapi so as to make this compatible with any type of node and the node_save() function so as to avoid having to deal with lower-level database calls.

Here is the main problem I encountered during the development of this module. Any help would be welcome. I'm also suggsting some changes in nodeapi in case what I want to do isn't possible using this hook.

I first tried with the submit operation of nodeapi and everything worked fine with the creation of the forum topic but I discovered that submit is also called when I modify a node so I tried with insert. Resulting in forum topics duplicating on each node modification.

The insert operation of nodeapi looks more appropriate for what I want to do. The problem is that insert appears to be called by node_save(). As a result, when I use the node_save() function to save my forum topic, I have an endless loop (the node_save calls nodapi insert operation and the insert operation calls node_save).

Is there a way to save a node without calling the insert operation? Or is there a way, when using the submit operation, to test if the node is created or if it's modified?

Suggestion for nodeapi:
Would Drupal's nodeapi need a new slightly different save_node function that doesn't call insert? Or better a second insert operation that isn't called by node_save, behaving almost the same way as submit does.

Thanks for your help.

#1

hunmonk - May 16, 2007 - 16:49
Status:active» closed

API is the module which powers http://api.drupal.org -- this is not the appropriate place to ask a drupal API support question. please post to the drupal.org forums, or visit #drupal, the IRC channel on irc.freenode.net.

 
 

Drupal is a registered trademark of Dries Buytaert.