node not fully loaded in hook_view() when previewing
Hello, In a module with its own node type, the node is not fully loaded when using preview. In hook_load(), I return my own extra fields to the node: return array('mynodetype' => $extra); In hook_view(), $node->mynodetype is set when viewing the node, but not when editing then previewing the same node. Isn't the node loaded as for a normal node view? I've searched drupal.org but didn't find anything terribly useful. I found this old forum post: Philosophy of 'Preview' http://drupal.org/node/126750 And this old core issue, which I had helped reviewing at the time, but which is supposed to be fixed (though it was not said how it was fixed): node previews broken by missing hook_submit http://drupal.org/node/104047 Is this a known issue? Blessings, Augustin.
Hello again, I have a different but related problem: If I update a node (e.g. published /not published) using the admin form at admin/content/node , hook_update() does not have the full node either, and notices are spewed out because none of my custom fields defined in hook_load() are set. Are hook_view() and hook_update() supposed to node_load() the nodes themselves? Looking back at some of my modules, I see some instances where I have done $node = mynodetype_load($node) to get a full node. Thanks, Augustin.
Quoting "augustin (beginner)" <drupal.beginner@wechange.org>:
Hello again,
I have a different but related problem: If I update a node (e.g. published /not published) using the admin form at admin/content/node , hook_update() does not have the full node either, and notices are spewed out because none of my custom fields defined in hook_load() are set.
Are hook_view() and hook_update() supposed to node_load() the nodes themselves?
Looking back at some of my modules, I see some instances where I have done $node = mynodetype_load($node) to get a full node.
You might need to change the weight of your module in the system table so that it executes later than the node and/or the taxonomy modules. Hooks are called in order of weight and within weight by the ascending sort order of the name of the module. The default weight is zero. Otherwise you may have a module installed that is badly mistreating the node object. -- Earnie http://r-feed.com Make a Drupal difference and review core patches. -- http://for-my-kids.com/ -- http://www.4offer.biz/
On Friday 27 March 2009 20:01:00 Earnie Boyd wrote:
You might need to change the weight of your module in the system table so that it executes later than the node and/or the taxonomy modules. Hooks are called in order of weight and within weight by the ascending sort order of the name of the module. The default weight is zero. Otherwise you may have a module installed that is badly mistreating the node object.
Thanks. I needed the reminder about module weights. I often forget about it. Still, my module name is cw.module, it previously had a weight of 0. I have just upped the weight to 10 and see no difference. In any case, since I define the node type cw_charity, cw_charity_load() should be called before cw_charity_view() or before cw_charity_update(), which I explained does not seem to happen in some special cases (node preview + node admin form). Augustin. -- http://openteacher.info/ http://overshoot.tv/ http://charityware.info/ http://minguo.info/
On Friday 27 March 2009, augustin (beginner) wrote:
Hello,
In a module with its own node type, the node is not fully loaded when using preview.
In hook_load(), I return my own extra fields to the node: return array('mynodetype' => $extra);
In hook_view(), $node->mynodetype is set when viewing the node, but not when editing then previewing the same node. Isn't the node loaded as for a normal node view?
No, because it might not even exist yet in the database ("create content"). However, submitted values as in $form_state['values'] will be merged into the node object on preview and save, so you might e.g. add more node properties in hook_nodeapi($op='validate'), or stuff. Cheers, j
On Friday 27 March 2009 15:46:54 Jakob Petsovits wrote:
No, because it might not even exist yet in the database ("create content").
Yes, this is another scenario that I hadn't mentioned but that I was aware of.
However, submitted values as in $form_state['values'] will be merged into the node object on preview and save, so you might e.g. add more node properties in hook_nodeapi($op='validate'), or stuff.
I'll test along those lines, thanks. Augustin. -- http://openteacher.info/ http://overshoot.tv/ http://charityware.info/ http://minguo.info/
augustin (beginner) wrote:
Hello,
In a module with its own node type, the node is not fully loaded when using preview.
In hook_load(), I return my own extra fields to the node: return array('mynodetype' => $extra);
In hook_view(), $node->mynodetype is set when viewing the node, but not when editing then previewing the same node. Isn't the node loaded as for a normal node view?
I've searched drupal.org but didn't find anything terribly useful.
I found this old forum post: Philosophy of 'Preview' http://drupal.org/node/126750
And this old core issue, which I had helped reviewing at the time, but which is supposed to be fixed (though it was not said how it was fixed): node previews broken by missing hook_submit http://drupal.org/node/104047
Is this a known issue?
Sort of. Remember that despite being called $node what you get for preview and insert/update hooks is NOT a node object. It's $form_state['values']. Unless you call node_save() yourself from soemwhere, in which case it IS a node object. Thus you need to structure your node data and your node form additions to parallel each other, or stuff breaks horribly in horrific ways. This is a known design flaw in the node system. It royally sucks on innumerable levels. I think the most likely solution in the long run is "if it's not a Field, sucks to be you, use Fields". Not a great solution, but it is what it is. --Larry Garfield
On Saturday 28 March 2009 03:47:54 larry@garfieldtech.com wrote:
Sort of. Remember that despite being called $node what you get for preview and insert/update hooks is NOT a node object. It's $form_state['values']. Unless you call node_save() yourself from soemwhere, in which case it IS a node object. Thus you need to structure your node data and your node form additions to parallel each other, or stuff breaks horribly in horrific ways.
This is a known design flaw in the node system. It royally sucks on innumerable levels. I think the most likely solution in the long run is "if it's not a Field, sucks to be you, use Fields".
Not a great solution, but it is what it is.
Hmmm, yes. Great comments. Now that you mention it, I had observed this before but it didn't really 'click' until now. Thanks. That's crazy, really. The same function hook_view() would be passed either a fully loaded node in case of a normal node view OR a half backed, FAPI-ish node in case of a node preview (either when creating a new node or editing an existing one).
Thus you need to structure your node data and your node form additions to parallel each other, or stuff breaks horribly in horrific ways.
I think I am starting to get this... ! ;) Is this design flaw still applicable in Drupal 7? Is there an issue about it? In conclusion, if I understand well the replies I got, the problems I have been experiencing are to be expected and I should take care myself to handle special cases accordingly. Thanks again to all three for your replies. Blessings, Augustin. -- http://openteacher.info/ http://overshoot.tv/ http://charityware.info/ http://minguo.info/
participants (4)
-
augustin (beginner) -
Earnie Boyd -
Jakob Petsovits -
larry@garfieldtech.com