Is it possible for two modules that interact with one another to both call hook_insert()?

  • I have a node type that calls ModuleA_insert() when the user hits the 'save' button.
  • Module B is a custom comment-like module that gets injected into a form. In module B, I have a ModuleB_insert(), but it never runs.
  • I am trying to keep module A from having to deal with the inserts/updates from module B.

I can get module B to insert by using hook_nodeapi(), but it would be easier if I could get hook_insert() to work, meaning module A and module B's data and actions are separated from each other - not to mention the overhead cost of having hook_nodeapi() run and check every time.


Rule of thumb: Don't call hook_anything() in other modules. :-)

If you call node_save($yourNode) then the node API will invoke hook_insert() in the module that implements that node type, if the node is being inserted. Otherwise hook_update() gets called for updates.

If you need to act on an insert for any type of node, and it sounds like you do, then you want to implement hook_nodeapi().

Examples has a node project and a nodeAPI project, so you can figure out which you need.

  • Are you saying do not ever use hook_anything() from my custom module?
    – user785179
    Jan 10 '12 at 23:47
  • 1
    I'm saying the node API will call the hook, so that your module can do what it needs to after the node is inserted (or updated, as the case may be). hook_insert() is supposed to be implemented by the module that creates the node type. hook_nodeapi() is called for any module that has it, so that those modules can then do whatever they want with the node.
    – paul-m
    Jan 11 '12 at 0:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.