How to get field value from referenced entity inside a field collection My structure is as follows:

I've got a custom contenttype with a multivalue field containing a field_collection. In this field_collection there are an amount field, a entity_reference_field and a computed_field. The referenced entity also contains several fields.

What I need to do:


Step 1:
In the computed field (inside the collection) I need to get the value of a certain field of the entity, referenced by the entity_reference field (also inside the field collection) and multiply this value with the value of the amount field.
Step 2:
In another computed field (on the node itself) I need to sum up all the values of all the computed fields inside these collections.


My Problem is primarily Step 1
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:

&lt;?php
function computed_field_YOUR_FIELD_MACHINE_NAME_compute(&amp;$entity_field, $entity_type, $entity, $field, $instance, $langcode, $items) {
  $entity_field[0]['value'] = 'value';
}
?&gt;
Parameters:

&amp;$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.