I wrote a module that creates node type using hook_node_info().
I implemented hook_validate.
I updated $node variable in hook_validate . I followed node_example.module for function signature (It gets the $node as call by reference).
I did print_r($node) in my hook_insert implementation.

I expected that I get the updated data in print_r($node), but the updates I did in validation stage is not there ..

I tried adding &$node in node_validate .. but it creates error,

Thanks

CommentFileSizeAuthor
#6 examples.node_example_signature.patch529 bytesrfay

Comments

damien tournoud’s picture

... and hook_validate() documentation says it should be ($node, &$form). That's a real mess.

At this time, I'm not sure that modifying the node during validation is even supported.

jbrauer’s picture

Title: node_validate is using call by value($node) whereas node_example_validate using call by reference(&$node) » node_example_validate() API documentation is incorrect
Version: 6.2 » 7.x-dev
Component: node system » documentation

The documentation for hook_validate() in the node_example module is incorrect. As can be seen http://api.drupal.org/api/function/node_example_validate/7 As noted by earlier hook_validate() expects this to be called like this:

hook_validate($node, &$form)

the node example module section on hook validate needs to be this:

node_example_validate($node, &$form)

The remainder of the text needs to be updated as well as the code sample.

jhodgdon’s picture

Project: Drupal core » Examples for Developers
Version: 7.x-dev »
Component: documentation » Code

The example modules are now being maintained in a different project, so moving this issue there. It's possible this has already been fixed... in fact, I think it has, but the new examples are not yet up on api.drupal.org -- we need to have that happen soon!

rfay’s picture

Status: Active » Fixed

hook_validate() is not used in the current D7 version of the node example module, so closing.

jbrauer’s picture

Version: » 6.x-1.x-dev
Status: Fixed » Needs work

According to CVS this is not fixed in the Drupal 6 branch.

rfay’s picture

Component: Code » AJAX Example
Status: Needs work » Needs review
StatusFileSize
new529 bytes

Here's the fix, 2 years later. However, I never found any trace of $node being passed by reference.

rfay’s picture

Component: AJAX Example » Node Example
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.