logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

[Documentation bug] hook_validate() should not change $node: msg#00097

Subject: [Documentation bug] hook_validate() should not change $node
Issue status update for http://drupal.org/node/84602 Post a follow up: http://drupal.org/project/comments/add/84602

Project:      Documentation
Version:      <none>
Component:    Developer Guide
Category:     bug reports
Priority:     normal
Assigned to:  Anonymous
Reported by:  plumbley
Updated by:   plumbley
Status:       active

Current CVS documentation for hook_example_validate() includes the
example
<?php
function node_example_validate(&$node) {
  [ ... if ($node->quantity) { ]
    // Let an empty field mean "zero."
    $node->quantity = 0;
  }
} 
?>
But since 4.7 it looks like any changes to $node made in hook_validate
are ignored. E.g. in modules/node/node.module we have
<?php
function node_validate($node, $form = array()) {
  ...
  node_invoke($node, 'validate', $form);
  node_invoke_nodeapi($node, 'validate', $form);
}
?>
which is pass-by-value rather than pass-by-reference. So although
node_invoke() passes by reference, no changes to $node can "escape" out
of node_validate.


I'm guessing this is by design, but if so the documentation should say
what to do instead. E.g. I *think* form_set_value() should now be used,
but its a bit non-obvious. For example, I used something similar to the
following elsewhere (in 4.7):
<?php
  form_set_value(array('#parents' => array('quantity')), 0);
?>
Is this now the recommended route to change nodes? (or not?). Mark.


PS Looks like the change to validation operation in 4.7 also caused
problems for node_import, which ideally should be able to validate a
node without requiring a form to be present, so a documentation update
might help getting validation working there too.




plumbley

--
Pending work: http://drupal.org/project/issues/documentation/
List archives: http://lists.drupal.org/pipermail/documentation/



<Prev in Thread] Current Thread [Next in Thread>