I have one custom content. It contains a multiple collection field. If I create a new entity (via entity_metadata_wraper), how can I set a new multiple collection field ?

by example :

$new_entity = entity_create('node', array('type'=>'custom content');
$new_entity_w = entity_metadata_wrapper('node',$new_entity);
$new_entity_w->a_new_multiple_collection_field[0]->some_field->set('...'); //(1) doesn't work
//$new_entity_w->a_new_multiple_collection_field[]->some_field->set('...'); //(2)doesn't work

Error for (1) : Unable to set the data property some_field as the parent data structure is not set

Error for (2) : PHP Fatal error : Cannot use [] for reading in /var/...

I didn't find...thank you for some help !

  • Have you tried: $new_entity_w->a_new_multiple_collection_field[0]->some_field[0]->set('...'); – pcambra Jul 17 '14 at 21:08
  • Pardon, I didn't notice the question is about a collection field. – kiamlaluno Jul 17 '14 at 21:10
  • Thanks for replying ! $new_entity_w->a_new_multiple_collection_field[0]->some_field[0]->set('...'); I get an error : PHP Fatal error: Cannot use object of the EnriryValueWrapper as array in /var/... – user2137454 Jul 17 '14 at 21:32

Your Answer

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

Browse other questions tagged or ask your own question.