I have a problem with field collection and entity reference fields. I have a field collection called 'field_co_intervenant' and i want to add several entities in this field collection and after saved my node. But i got an error with the index i think, because when the node is saved, there is just one reference entity in my field collection. You can see the code here :
$intervenant is the array of my 'nid'.
if(!empty($intervenant)) {
//Create entity
$fieldcollection = entity_create('field_collection_item', array('field_name' => 'field__doc_fc_intervenant_tab'));
//Attach entity
$fieldcollection->setHostEntity('node', $node);
//Fill field
$i = 0;
foreach ($intervenant as $val) {
if($val != null) {
$fieldcollection->field_fc_intervenant_tab[LANGUAGE_NONE][$i]['target_id'] = $val;
$i++;
}
}
//Save entity
$fieldcollection->save();
}
How can i save all my values in the field collection and not just one ?
Thanks