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?

1
  • 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.
    – avpaderno
    Commented Apr 5, 2011 at 16:19

1 Answer 1

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.

3
  • 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
    Commented Apr 6, 2011 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
    Commented Apr 6, 2011 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
    Commented Jan 7, 2014 at 7:15

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.