In my custom module I am creating a node using node_save. I have also implemented hook_node_update to catch a user updated node. But every time I call node_save, it also calls my hook. Is there a way I can tell that this update was called using my node_save. In Drupal 6, I used to add something like $node->skip_it = TRUE in before node_save, and this was available in the update hook. But not any more. Any pointers.
2 Answers
You can check using below condition while using node_save
If $node->nid is omitted (or $node->is_new is TRUE), a new node will be added.
So, in your hook_node_update check for above condition before executing your code.
-
1But if I am updating an existing node, then both nid and is_new will not work.– V-KCommented Oct 11, 2012 at 17:37
If all the user updates you need to catch happen via the node edit form, you could implement hook_form_FORM_ID_alter()
and append your own submit handler which won't be called on node_save()
. The downside is that you'll probably need to read any user modifications from $form_state['values']
.
function mymodule_form_MY_CONTENT_node_form_alter(&$form, &$form_state, $form_id) {
$form['#submit'][] = 'mymodule_MY_CONTENT_submit';
}
function mymodule_MY_CONTENT_submit($form, &$form_state) {
// do stuff here
}
$node->skip_it = TRUE;
wouldn't work in Drupal 7