1

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:

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


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

?>

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

  • 2
    Please read How to Ask and possible faq and accept some answers to your other questions. You are not likely to get many useful answers with a big red 0% below your name. – Chapabu Dec 19 '12 at 16:37
  • No problem, I hope I didn't come across as obnoxious. Some people may see the low acceptance rate and pass right by without answering, which means you won't get an answer - don't really want to have that happening :) – Chapabu Dec 19 '12 at 20:29
0

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 ...

  • Of course I have devel enabled, I have a commented dpm function in the code, I'm going to check the entity_get_info(). Thanks – Oskar Calvo Dec 19 '12 at 23:23
  • could it be that you have it deployed via a feature ? – mojzis Dec 20 '12 at 7:44
  • search for ['entity keys']['bundle'] – mojzis Dec 20 '12 at 7:49
  • Hello mojzis, is not yet a feature. I have check the dpm and I find that the ['formulario']['entity keys']['bundle'] is "type". The question is How I should have to call it: ::setHostEntity('type',$entity); ? – Oskar Calvo Dec 20 '12 at 16:05
  • and if you dpm() the entity after you load it ? does it have the type property ? – mojzis Dec 20 '12 at 16:39
0

Use entity_load_single instead of entity_load to load single value instead of array.

This will solve the error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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