Get Node ID in hook_field_formatter_view() I'm currently working in a custom video player. For that I've created a content type which uses a field_collection (for the video file and other stuff) and a field_caption for a XML file. 

The video file field uses a custom field formatter, which I'm using to theme up the player. I need the field_caption file to be added there so I'm trying to get the node id of the field_section Field Collection in the hook_field_formatter_view() to get that info....with no luck!

If I print $entity->vid from the function parameters I will have NULL, because the field is within a field_section I believe.

Is there a way round this? 

Thanks in advance!
As the Field Collection docs says:


  A field collection is internally represented as an entity, which is embedded in the host entity


So what you need to do in your field, is:


Test if it's container is a node. This case works already.
Test if it's a Field Collection entity.
Fallback to situation when you can't obtain parent container or it's an unexpected entity.


Now we'll take care about 2. point. If you can safely assume your field is always in a node, you can use code from answer by Chris Muench:

$model = entity_load_single('field_collection_item', $model_id);
$node = $model-&gt;hostEntity();
echo $node-&gt;nid;


Note that you are writing formatter, and it means you have no guarantee that host entity will always be a node. If it's not, go to point 3 on my list.