3

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.

1
  • I don't understand why this $node->skip_it = TRUE; wouldn't work in Drupal 7
    – SebCorbin
    Commented Aug 14, 2013 at 12:14

2 Answers 2

1

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.

1
  • 1
    But if I am updating an existing node, then both nid and is_new will not work.
    – V-K
    Commented Oct 11, 2012 at 17:37
0

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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