1

The node_api hook provides a bunch of triggers which allows you to customize what might happen on, for example, a presave. The node_api presave opcode triggers an action to occur after clicking on the node 'save' button but BEFORE the information in the node form is inserted into the database. I would like to create a trigger which will be a post-save trigger, to trigger my custom code after clicking the save button but AFTER the node info has been saved into the database. Does anyone have any ideas of how I might create such a trigger?

(I have read the documentation about how to create a trigger, I just don't know to code the trigger I am describing above.)

1

Just to break the process down a bit (based on your other questions:1,2); when you submit a node form:

  1. node_form_submit() calls node_save().
  2. node_save() immediately calls node_invoke_nodeapi($node, 'presave'); to inform other modules about the presave.
  3. node_save() then sets up a few properties on the node object, and the node record is written to the node table in the database using drupal_write_record().
  4. At the very, very end of the function (after the data has been written to the node table), node_invoke_nodeapi() is called again with either 'insert' or 'update', depending on the current operation being run.

If you look through those functions, and the summary above, you'll see that the node data is 100%, definitely committed to the database before the 'insert' or 'update' operations are run for hook_nodeapi().

If that's not happening for your installation I would strongly recommend replacing core with a fresh version, as it sounds like something's gone horribly wrong!

Getting to the actual question; the only way you can add a post-save hook is to add another line in the core node_save() function to invoke it. But you would be adding it immediately after the call to node_invoke_nodeapi($node, $op); (where $op is 'insert' or 'update') anyway, so I'm not sure that would help.

| improve this answer | |
  • I can't believe that my core is messed up since issue is happening on my personal copy of drupal as well as the the one I am working on (which is on a different server). I posted my code at drupal.stackexchange.com/questions/30402/… , do you see anything in the code which would create my issue? – user1015214 May 9 '12 at 21:13
  • Ah ok, so it's CCK stuff that's missing from the database when your insert/update $op is running. What's your module called? Is the first letter of it 'a' or 'b' by any chance? – Clive May 9 '12 at 21:23
  • yes, it starts with a, why would that make a difference? – user1015214 May 10 '12 at 0:59
  • Ohhh it does :) I'll answer one of your other questions, it'll make more sense in that context – Clive May 10 '12 at 8:17

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.