How to add content programmatically to a field collection that it's in an entity (build with eck) I'm trying to save information into an entity build with eck, this entity has a field_collection with more fields.

I have take a look around internet, and I only find examples that works with node entity and user entity, but when I try to use the same code with my entity, it doesn't works.

This is my code:

&lt;?php
$idform = 1;
$entity = entity_load('formulario',array($idform));
//dpm($entity);


$newfield_collection = entity_create('field_collection_item', array('field_name' =&gt; 'field_form_field'));
$newfield_collection-&gt;setHostEntity('formulario',$entity);
$newfield_collection-&gt;field_name[LANGUAGE_NONE][0]='name3';
$newfield_collection-&gt;field_form_id[LANGUAGE_NONE]['0']['value']=3;
$newfield_collection-&gt;field_sff_name[LANGUAGE_NONE]['0']['value'] = 'value name 3';
$newfield_collection-&gt;field_field_id[LANGUAGE_NONE]['0']['value'] = '13434';
$newfield_collection-&gt;field_field_type[LANGUAGE_NONE]['0']['value'] = 'value type 3';
$newfield_collection-&gt;save(FALSE);

?&gt;


And this is my error message:


  EntityMalformedException: Missing bundle property on entity of type
  formulario. in entity_extract_ids() (line 7633 of
  /home/oscar/webapps/www/drupal/drupal7/includes/common.inc).


I have debuging the code and seems that the problem is with setHostEntity But I don't know if it's because I build the entity with eck module.

Thanks

Oskar
The problem here is that entity_load returns an array, not the single entity. So you should do something like this :

$entities = entity_load('formulario',array($id));
$entity = end($entities);


and then the rest of your code ...