[development] Important nodeapi change

Karoly Negyesi karoly at negyesi.net
Wed Dec 7 06:54:11 UTC 2005


Sorry for not announcing this change on Monday.

nodeapi op 'form' is no more. Use hook_form_alter instead. This lets you  
not just add to the node form but change at will.

See the core modules for examples. The conversation process is the  
following: let's suppose we have foo.module , and it compiles its nodeapi  
form in _foo_form which takes one argument, $node. and the last command is  
return $form (core actually had such functions). Then we can rename  
_foo_form to foo_form_alter and wrap the code as follows:

function foo_form_alter($form_id, &$form) {
   if (isset($form['type']) && $form['type']['#value'] .'_node_form' ==  
$form_id) {
     $node = $form['#node'];
     // _form_form code follows:
     $form['foo']['myfield'] = array(...);
     // the final return is not needed because $form is a reference.

I added this to the handbook, too.



More information about the development mailing list