I've found several posts with this same question, but the answers always diverge to some other topic or they don't work for my needs.
After a node is saved, I want my custom module to insert a row into one of my custom tables which contains the nid of the new node. When hook_node_submit
is called, the nid doesn't exist yet. hook_node_insert
does have the nid, but only gets called the first time the node is saved, but I potentially need to take action each time the node is saved.
My plan is to separate my functionality into its own method and implement both hooks, but I'm trying to learn to do things properly with Drupal and so I'm wondering if there is a hook that actually fits with my requirements.
Is there a hook which is called every time a node is saved and called AFTER the save is complete?
hook_node_insert
andhook_node_update
(acts every time a node is being saved).hook_node_submit
but nothook_node_update
?hook_node_insert
as well as inhook_node_update
.hook_node_insert()
andhook_node_update()
are the correct hooks for this,hook_node_submit()
is called during the form submission process before the node is saved. Don't forget you need to clear caches any time you add/remove a hook