Posted by mkruisselbrink on October 27, 2008 at 9:28am
| Project: | Drupal core |
| Version: | 8.x-dev |
| Component: | documentation |
| Category: | bug report |
| Priority: | normal |
| Assigned: | nenne |
| Status: | active |
| Issue tags: | needs backport to D6, needs backport to D7 |
Issue Summary
The hook_validate documentation seems to be invalid in several ways. There is a paragraph that reads:
Changes made to the $node object within a hook_validate() function will have no effect. The preferred method to change a node's content is to use or hook_nodeapi($op='submit') instead. If it is really necessary to change the node at the validate stage, you can use function form_set_value().
However hook_nodeapi($op='submit') does not seem to exist, and also form_set_value is not an option, as from hook_validate you don't have access to a form_state variable you can change.
Comments
#1
The hook_nodeapi() reference has already been fixed.
I agree on what you're saying about using form_set_value() though. This needs to be fixed in Drupal 7, then having the fix backported to Drupal 6.
#2
More discussion on #336305: Documentation error for hook_validate() regarding form_set_value(), which I just marked as a duplicate of this issue.
#3
#4
Removed the erronous part and corrected a MT.
#5
Looks good to me. Assuming the test bot agrees...
Thanks!
#6
Committed to CVS HEAD. Thanks.
#7
Automatically closed -- issue fixed for 2 weeks with no activity.
#8
Whoops. In investigating #1196720: hook_node_validate documentation wrongly suggests set_form_value? I realized that this argument about $form_state not existing doesn't apply to Drupal 7/8 (the $form_state arg is there in Drupal 7/8). So maybe this fix shouldn't have been done for Drupal 7?
Also, whatever is correct for hook_validate should be done for hook_node_validate too.
Also, this fix never got backported to Drupal 6, where $form_state isn't there in either hook_validate() or hook_nodeapi($op = 'validate').
#9
tagging, also note that the person who reported #1196720: hook_node_validate documentation wrongly suggests set_form_value? said that using form_set_value() didn't work.
#10
But that person, me, didn't try very hard to make form_set_value work - I had already found this issue and kind of thought that form_set_value shouldn't work.