I tried adding a second computed field to a node and it's causing an error.  Here's the code of the first CF:

Computed Code (PHP)
$field_a = field_get_items($entity_type, $entity, "field_device_count");
$field_b = field_get_items($entity_type, $entity, "field_ct_dashboard_vm");
$entity_field[0]["value"] = $field_a[0]["value"] + $field_b[0]["value"];

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

This works fine.

The second CF uses exactly the same code except I used x instead of + to get a multiplied result. 

I also tried changing $field_a to $field_c and $field_b to $field_d and $entity_field to $entity_field2 but nothing has worked so far. 

Questions:  How many CF's can one have on a single Content Type, and if multiple CF's are supported, what is the code to get the above example working please?

Thanks for reading and any feedback.

Comments

GuyManDude’s picture

The second CF wasn't working becuase I used x instead of *

I would like to know how many successful CF fields you have seen on a single Content Type though please.  I would also like to know if and how we can create multiple calculations with a single CF.  

destash’s picture

i have 3 CF in one content type. i using CF to get data value, manipulate value and other what i want. Because i not good in scripting some case i using rules to add data value for field in content what i hide from node add/edit to substitute CF,,

this my 3 CF:

1. i using to get node title

$entity_field[0]["value"] = $entity->title;

2. i using to get date of birth and manipulate with rules for other field what i say

$original_date = $entity->field_tanggal_lahir[LANGUAGE_NONE][0]['value'];
$calculated_date = date('j F Y', strtotime($original_date));
$entity_field[0]['value'] =  $calculated_date;

3. i using to manipulate from field serial

$field_a = field_get_items($entity_type, $entity, "field_medrek");
$entity_field[0]['value'] = str_pad($field_a[0]['value'], 6, '0', STR_PAD_LEFT);