Drupal 7 using computed field module ... Having issues :(

dalearyous

[H]ard|Gawd
Joined
Jun 21, 2008
Messages
1,922
i must be missing something big because i cannot get this to work.

Computed Code (PHP)
$entity_field[0]['value'] = "$field->field_number_1 + $field->field_number_2";

Display Code (PHP)
$display_output = $entity_field_item['value'];

(field_number_1 and field_number_2 are of type integer)

the error i keep receiving: Notice: Trying to get property of non-object in eval()

all i want to do is basic arithmetic with fields i currently have. no luck.
 
Maybe you just left this off, but shouldn't it be:

$display_output = $entity_field_item[0]['value'];

EDIT: Also, with the quotes here, you are going to be concatenating the values into a string, not doing math:

"$field->field_number_1 + $field->field_number_2"
 
removing the quotes gives me a value of 0 after it errors with this: "Notice: Trying to get property of non-object in eval()"
 
Have you tried asking in the main drupal.org forum?

When you say computed code, do you mean in the template.php file? And display code; is that in a tpl.php file?

you may also need to reference the language. ['und'][0]['value'].

Have you tried printing each one of these variables independently? I'd use the devel module, and dpm() to help out with that.
 
the main drupal forum has been pretty worthless. within an hour your topic goes to 2nd page and you never get replies.

i am using the module computed field. when you setup a computed field, you can use PHP to make computations and display the results in the field.
 
the main drupal forum has been pretty worthless. within an hour your topic goes to 2nd page and you never get replies.

i am using the module computed field. when you setup a computed field, you can use PHP to make computations and display the results in the field.

Have you checked the issue queue for the module than? Often times I find my questions answered through those.

Has this worked for you previously? I've never used that module, so I'm not familiar with what it's expecting. But I'd look towards this; "$field->field_number_1 + $field->field_number_2";

The error says you're trying to get a property of a non-object. Should those fields be referenced as $field['field_number_n']?
 
Code:
$entity_field[0]['value'] = 
  array_pop(array_pop(field_get_items($entity_type, $entity, 'field_number_3'))) +
  array_pop(array_pop(field_get_items($entity_type, $entity, 'field_number_4')));

that ended up working. when i realized the fields were objects, not variables, everything kind of clicked.
 
now that it is working, how would i create a loop to do "sum of".

so if i have a field called expense and each expense is a row of data. i want to loop through and add up every expense and display total. ?
 
Back
Top