On 04/10/2010 17:41, Pierre Rineau wrote:
Le lundi 04 octobre 2010 à 16:50 +0200, luca capra a écrit :
Good evening,
I'm writing a custom module, with a call to hook_nodeapi (on php 5.3, latest drupal 6) I update some cck fields, but looking at the saved node page, these fields are empty.
Seems that after the hook, cck fields lose their values.
function mymod_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL){ switch($op){ case "insert": case "update":
my_fill_cck(&$node );
// here cck are populated // krumo( $node ); break; case "load": // viewing node, cck are empty :( // krumo( $node ); return array(); break; } }
Any idea is really appreciated. Thank in advance.
Best regards, Luca
Spotted syntax error: my_fill_cck(&$node );
Forcing reference at call time is deprecated already with PHP 5 (if I remember well), and using PHP 5.3 could lead the interpreter to ignore the function call.
The same for the hook(), if your module is for PHP>=5.2, don't write the& in the function signature, $node is an object therefore it's been passed by reference anyway, using& in method signature makes it being a pointer, which means that some module write $node = NULL will change the pointer value (not the object itself) and it may break the execution flow after.
Adam was right, use presave to ensure your data is being modified after the real save. Or you also could ensure your module has a lower weight than the content module, to ensure content_nodeapi() being called after your own.
Pierre.
The $op presave was my problem. This is a syntax error my_fill_cck( &$node ); and this should be my hook: function mymod_nodeapi($node ... because &$node is a pointer, and what I need is a reference (that is how is passed an object ). It's right ? Interesting, I learnt something new :) Regards, Luca