I got the latest version of 4.7 after the bugs in these issues are fixed:
http://drupal.org/node/76614
http://drupal.org/node/76613
Well, these issues seem to be fixed, but now there's a new problem. I can't get the value of $node->nid in the computed field when the node is inserted. However, when i edit the node again, then the value $node->nid is available.
Comments
Comment #1
wrunt commentedI'm afraid this problem is a tough one. A node in drupal doesn't have a nid until it has been created, but we're computing the value just before the node is created, so that the value can be saved with the node.
A possible approach would be to call node_save before computing the value. I'm not certain that it will work, but give it a shot. In your computed field code call node_save($node) before you try to access $node->nid. If it is saved successfully then $node->nid will be set, and hopefully there won't be any problems with saving the node early.
It might be a good idea to give your computed field a high weight, so that all the other fields have been processed before you call node_save.
Comment #2
vph commentedThis is odd, because before the html and view fix, I didn't have that problem. I still have the old version and can verify that now.
LIke I reported, the problem that I had was that the html didn't get printed out properly, but I was still able to store the $node->nid in the computed field.
But after the changes, I can no longer do that at insert. So I think something is wrong between the previous version and the last two updates.
Comment #3
wrunt commentedOk, the previous version actually re-computed the computed field every time you went to view it. So on the first submit your nid wouldn't have been stored, but on the subsequent load it was visible.
If you disable storing the field in the database then it should work for you, because in that case the field is still re-computed every time. Not storing the field should be ok, because the nid is stored in the database anyway.
Comment #4
vph commentedOkay, I turned off "storing". Now I can get the value of $node->nid on insert. Fine. BUT ..... now views doesn't work (can't show the field). I guess that is so because the field is not in the database to be viewable. I don't know how this module works enough to make complete sense what you are saying.
But I think it is very reasonable to have :
+ $node's attributes available for computation at insert time (as well as edit time).
+ viewable through the views module
+ html links shown properly (I presume this has nothing to do with the other two points).
Can you make it so that we have all three? Otherwise, if you want to view the computed fields involving $node->nid or similar attributes, you MUST edit the node. It doesn't seem right.
Comment #5
vph commentedIn other words, without fixing this bug, you can not use the $node's attributes such as nid without EDITING the nodes simply for the purpose of having computed fields done properly OR not storing the attribute in the database.
Comment #6
wrunt commentedI've updated cvs with a minor change that will make it possible to store your field (so views can see it), and also make $node->nid visible on the first submit. If you want the change now then change this line:
function _computed_field_compute_value($node, $field, &$node_field) {to this:
function _computed_field_compute_value(&$node, $field, &$node_field) {Then in your computed field's code add this at the beginning:
This will save the node on the first submit before your code executes, and in saving the node drupal will assign its nid.
I hope this solves your problem vph, I really didn't mean to make things difficult for you. Out of curiosity, what are you using the computed field for?
Comment #7
vph commentedwrunt,
If my writing shows some frustration, I apologize because I didn't mean to. In contrast, I appreciate your help and module alot, and the effort you put in making it better.
I tried the mod above and it seems to work now. Thanks alot.
Comment #8
vph commentedI forgot to answer your question about what I use $node->nid for. I simply use it to output a URL with node->nid as an argument to an external program. Eventually, I'll find someway to incorporate into a module.
Thanks again.
Comment #9
wrunt commentedI've added an example on the project page that uses the nid, so hopefully this won't trip anyone else up for too long.
Comment #10
(not verified) commented