2

I have a type node called flat, a field called latitude. I want to update the value of this field in a module each time the node is updated.

I try to use the hook_node_update() but nothing happens :

function flat_node_update($node){
    print_r($node);  
    return $node;
}

Do you have the answer?

  • hook_node_update() should not return any value; changing the values of the fields in $node, and then returning the modified object doesn't work. – kiamlaluno Apr 5 '11 at 16:19
6

hook_node_update() is called after the node has been updated.

You want hook_node_presave() instead. If the nid is not empty, it is an update.

| improve this answer | |
  • But just for a test, I try to print 'hello', and nothing happen with these functions. It's like my hook are not called. – Bulba Apr 6 '11 at 9:24
  • 1
    Use drupal_set_message() or dpm() for debugging, not print. Did you clear the cache after you added your hook implementation? – Berdir Apr 6 '11 at 12:36
  • Is the function in a module called "flat"? In the case above the module file would be called flat.module and would be in a directory called module which is enabled. If nothing is being echoed to the screen at all this may be the reason. – Gold Jan 7 '14 at 7:15

Your Answer

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

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