access the node id of a field collection
It works for me. You can do it as follows-

/**
 * Function hook_preprocess_field.
 */
function [theme_name]_preprocess_field(&amp;$variables) {
  if ($variables['field_name'] == [FIELD_COLLECTION_NAME]) {
    if ($variables['element']['#entity_type'] == "node") {
      $node_id = $variables['element']['#object']-&gt;id();
      //Rest of the code.
    }
  }
 }

Hope it works for you too.