Use Condition in Computed Field with Field Collections I have an entity with a field colleciton (fc_details), and in that field collection I have fields amount(field_amount) and Type (field_type)

There are several examples to sum up field colleciton values in computed field like:

$sum = 0;
$wrapper = entity_metadata_wrapper($entity_type, $entity);
  foreach($wrapper-&gt;field_fc_details as $collection) {
    $sum += $collection-&gt;field_amount-&gt;value();
  }

$entity_field[0]['value'] = $sum; 


But I want to sum up values, where field_type values = "Z".

I tried variations of "if($wrapper->field_type->value()='Z' " inside foreach, but then site gives 500 error.

Any ideas ? Thanks in advance.
Try the following and let me know how you go.


if($collection->field_type->value() == 'Z') {
  $sum += $collection->field_amount->value();
}