Node_save : how to ensure concistent CCK field formatting for tokens
| Project: | Content Construction Kit (CCK) |
| Version: | 6.x-3.x-dev |
| Component: | Token Integration |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
I have a CCK decimal field that is included (via pathauto and tokens) in the node path on node insert/update. For the sake of illustration, lets say the value of this field is $1200.00
When the node is saved manually, the token returns (and thus the path includes) this value formatted as 1200. Note that any trailing zeros after the decimal place are omitted.
When the node is saved via node_save() this value is formatted as 120000. Note that all trailing zeros are included.
This is causing issues with path consistency when the nodes are created manually, and updated programatically . The path module is complaining (and rightly so) that I have defined a duplicate path for my node. I have confirmed that after receiving the warning, that I do in fact have more than one path defined for the node in question.
My code is executing via hook_node_api (insert/update/delete). I am doing a simple node_load() to retrieve the node, modifying some field values, and the calling node_save().
How can I ensure that the values returned to tokens are formatted consistently whether the node is saved manually or via node_save? Is there a CCK formatting function I should be calling prior to my node_save()?
Thanks all!

#1
Here is the devel rendering of the field in question.
During Manual Save:
array(1) {[0]=>
array(2) {
["value"]=>
float(1270)
["_error_element"]=>
string(27) "field_order_total][0][value"
}
}
And during Programmatic Save (node_save):
array(1) {[0]=>
array(1) {
["value"]=>
string(7) "1270.00"
}
}
I think I'm missing something pretty basic here. Clearly the issue is that my field is stored as a FLOAT in the first case, and a STRING in the second. What is the best-practice way to ensure the appropriate data types are assigned to CCK fields after node_load() and prior to node_save()?
#2
The problem is that on node_load(), CCK reads the fields from database and decimals are stored as strings in the node object. If you do a node_save(), this format is ok to be stored in the database, however when pathauto executes at nodeapi('update') time and invokes token to get the values, the raw token is passed as is, as a string. Then, probably pathauto removes the dot and you get "120000" out of "1200.00".
The only way I can think this could be solved is not using the raw format, but a different field formatter from those available from "Display fields" screen for token values.
#3
Automatically closed -- issue fixed for 2 weeks with no activity.