I have added this hook myself to my core for several custom modules.
It is especially useful when you need to act on a nodeid just after initial creation, such as applying changes to a node using the tokens module.
Without this, the nodeid will not exist until after the node has been created at which point you've lost the ability to hook it.
I currently use it in production for a much simpler way to deal with changing upload paths based on the node information. This never worked on initial node creation simply and smoothly until I added this hook.
I implemented this as a one line change to node.module:
// Call the node specific callback (if any).
node_invoke($node, $op);
node_invoke_nodeapi($node, $op);
node_invoke_nodeapi($node, 'postsave');
// Update the node access table for this node.
node_access_acquire_grants($node);
Alternate simple methods to achieve the same result are welcome.
Comments
Comment #1
Daren Schwenke commentedComment #2
maartenvg commentedAPI changes go into HEAD.
Comment #3
berdirThis is exactly the same as hook_node_save/update?
(Sorry for pinging the participants, I'm trying to clean up a few old
issues)
Comment #4
holtzermann17 commentedActually, contrary to #3, this is NOT the same as hook_node_presave, because (as the name indicates) the contents of the node actually haven't been saved at the time of presave. I implemented my own hook_node_postsave so that I could grab the actual new page contents and do stuff with them. You can't do that with the node_presave (or even node_update) events... see comments.
Adding a hook_node_postsave is fairly trivial, you just do something like this:
... i.e. moving the contents of the current node_save function into a new node_save_transactional function... and making appropriate changes to node.api.php, like so:
Comment #17
smustgrave commentedThink this can be closed as outdated.
I see there is a postSave function in the entity that could probably be extended if desired.