code works in the db, but getting warnings when disk-based

rpmute - August 14, 2009 - 14:06
Project:Computed Field
Version:6.x-1.0-beta3
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

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.

<?php
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...
}
?>

#1

fastangel - August 20, 2009 - 21:10

The function is incorrect. The function correct is:
computed_field_field_package_total_compute($node, $field, $node_field)

#2

rpmute - August 25, 2009 - 19:26
Category:bug report» support request
Status:active» closed

yeah, 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.

#3

ArthurC - September 12, 2009 - 21:55

I'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.

 
 

Drupal is a registered trademark of Dries Buytaert.