Same block of code should work disk-based the same way it works in the database field.
However, I'm getting # warning: Invalid argument supplied for foreach() in /Users/adam/Sites/fredfoxvideo/sites/all/modules/custom/computed_code/computed_code.module on line 28.
where computed_code is the module i made to store all my code. Everything works fine when I copy the same exact block into the field's textarea
Error only comes in on the foreach, just a regular multi-value field.
function computed_field_field_package_total_compute() {
// other code here....
$adjustments = array();
foreach ($node->field_package_price_adj as $adj) { /*error comes on this line but it should be fine. */
$adjustments[] = $adj['value'];
}
// little more here...
}
Comments
Comment #1
fastangel commentedThe function is incorrect. The function correct is:
computed_field_field_package_total_compute($node, $field, $node_field)Comment #2
aterchin commentedyeah, about 2 hours later I realized maybe the function might need an argument or two. ouch. forgot to update this issue back then. thanks again, fastangel.
Comment #3
ArthurC commentedI'm asking here for very elementary stuff. I hope you don't mind.
When I'm configuring my computed field, do I call the function like this?
$node_field[0]['value'] = computed_field_field_fieldname_compute($node, $field, $node_field);Or should the computed field value be assigned in the function, and the function return nothing, ie, the last line of the function is
$node_field[0]['value'] = "hello world";The only value I need in the function is another field from the node. Do I need to pass it into a parameter with an argument when I call the function? What does the calling argument look like, if the field I want to work with is this: $node->field_otherfield[0]['value']?
Thanks very much.