http://api.drupal.org/api/4.7/function/hook_validate says:

It can also be used to make changes to the node before submission, such as node-type-specific formatting.

Both my recollection and an attempt to do that just now are contrary to that claim.

Comments

Wesley Tanaka’s picture

Ah yes, hook_submit does exist (I didn't see it the first time in the list). I'd suggest:

1. changing the hook_validate documentation so that the $node parameter is no longer preceded with '&'
2. removing the claim that it's possible to make changes to the node
3. adding a reference to hook_submit for people that want to make changes to a node.

plumbley’s picture

Status: Active » Needs review
StatusFileSize
new1.35 KB

+1 for this fix (remains in HEAD documentation). Combined with an out of date node_example.module, I think this has been confusing quite a few people for a while.

Patch for HEAD attached. Please also apply to 4.7, since it is wrong there too.

Best wishes,

Mark.

pwolanin’s picture

StatusFileSize
new1.79 KB

I'm not sure the & symbol matters- it can be preferable to pass large object by reference just for speed's sake.

Also, in PHP5 all objects are passed by reference no matter the declaration.

Also, the changes are not quite correct, since form_set_value() can be used to make changes at the validate stage:

http://api.drupal.org/api/HEAD/function/form_set_value

Attached patch commited to HEAD version (FYI, anone with CVS access can commit to the docs)

pwolanin’s picture

Status: Needs review » Fixed

also commited the same changes to the 4.7 branch

plumbley’s picture

Minor follow up (no action)... Personally I do think removing the & symbol (as in the applied patch) really does matter, since to have left it in would strongly imply pass by reference. Since this is what was true historically (Drupal 4.6), I think the documentation should use belt and braces (comments and code) to make this change as clear as possible.

Wesley Tanaka’s picture

Removing the & is important because it makes it clear that changes to the parameter *cannot* be propogated outside of the function.

(in an unimportant but slightly relevant note: I remember chx posting somewhere that parameters without the '&' are actually faster -- some notice produced by his development tool, but I can't find that bug trail).

Anonymous’s picture

Status: Fixed » Closed (fixed)
webchick’s picture

Status: Closed (fixed) » Needs work

We have a problem...

The API docs should be about code as it currently stands. There should be no references to Drupal versions past; information about API quirks that changed between versions belongs in the "Converting your modules" part of the handbook. Imagine how bloated the API docs would be if we documented every time that an API changed between versions!

So could you please re-word these changes so they're not "Since Drupal 4.7..." and instead "You may not..." or whatever?

pwolanin’s picture

Status: Needs work » Fixed
StatusFileSize
new1.01 KB

fixed and committed in 4.7 and HEAD per the attached patch.

Anonymous’s picture

Status: Fixed » Closed (fixed)