Based on what I read in the computed_field documentation, you have two options when creating the necessary code to compute the field. You could create the PHP into the text area of the field (I really dislike PHP in the database...but that's just me) or you can create a custom module with a specific function in it. Per the documentation:
Drupal 7
To use a function in a custom module instead of writing the code in text area create a function that looks like:
<?php
function computed_field_YOUR_FIELD_MACHINE_NAME_compute(&$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
$entity_field[0]['value'] = 'value';
}
?>
Parameters:
&$entity_field - The computed field. Used to store the computed value.
$entity_type - The entity type: node, user, comment, etc.
$entity - The actual entity (a node, user, comment, etc.)
$field - General field settings.
$instance - Field instance settings.
$items - The list of items.
Note:
Make sure $entity_field is passed by reference.
What is awesome about this method is we have the entity available to us via $entity (in your case, it would be an entity of type field_collection). From this approach, I would:
- Create a custom module with this function
- I would then create logic around calling the $entity variable, loading the entity (if required) and then getting it's entity reference, which will probably require another entity load.
- Do compute field logic that you'd like.
Once this is done, you can use the same custom module to write another computer_field_YOURFIELD_compute()
function for your initial field (on the node) that computes the combination for all field_collection computed field values.