I have a content who contains an unlimited collection field. Via a custom module, how can I get and set the informations which are in field collection in the content (nid) ?

I have read the api documentation of field collection but I don't understand how it works (I'm french..) By example I see this function : field_collection_item_load, the parameter is an item but...what is an item ? xD

Another question, my field collection contains an another field collection. Is there a particular way to get and set this "sub"-field collection ?

If you can me a very sample example of get and set, I thank you very much


1 Answer 1


Suppose we are in a hook_node_view(), a hook_preprocess_node() or something and we have access to $node, and my collection field is 'field_collection_field':

if (!empty($node->field_collection_field)) {
  $collection_fields = field_get_items('node', $node, 'field_collection_field');

  // Extract the field collection item ids
  $ids = array();

  foreach ($collection_field as $fc_field) {
      $ids[] = $fc_field['value'];

  //Get the entities
  $collections = field_collection_item_load_multiple($ids);
  // dpm($collections); Devel output the items
  //Loop over the array - if you have more than one entity
  foreach($collections as $collection) {
    //Iterate over all member vars of the FieldCollectionItemEntity object
    foreach($collection as $key => $value) {
 }//end if

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.