I've just noticed that hook_node_presave($node) is fired twice when adding new nodes: Once it's called from node_form_submit(); the second time from entity_save().
It turns out that $node->nid is not set in first call, but it is already present in the second one.

Is this a normal behavior for hook_node_presave($node) in Drupal 7? Does the node containing node reference fields make a difference?

  • It should only be invoked from node_save(), field_attach_presave() and user_save() (I have no idea what for in the last case). How exactly did you test it? What is stack trace of these calls you describe? – Mołot Aug 29 '14 at 13:41
  • You can use ddebug_backtrace to see why the hook_node_presave is triggered twice. As @Mołot mentioned, Drupal 7 core only trigger it twice. It may happen by some contrib / custom module. – Jimmy Ko Nov 14 '16 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.