Say I've got the following block of code:

$language = language_default();
$values = array([...]);

$entity = entity_create('node', $values);
$entity_wrapper = entity_metadata_wrapper('node', $entity);

$container = entity_create('field_collection_item', array('field_name' => 'field_container'));
$container->setHostEntity('node', $entity, $language);
entity_save('node', $entity);

The above block of code invokes three different save() methods. Is this strictly necessary? Does entity_save cascade to $container_wrapper->save() and $entity_wrapper->save() if I do not explicitly call these? Are all three necessary?

Things appear to work find if I skip $entity_wrapper->save(true)...but am I missing something?


You need just one save call. All of them invoke the same code, the controller's save method (or node_save in node's case).

The wrapper modifies the original entity by reference, so it doesn't need an explicit save of its own (and the other way around).

|improve this answer|||||

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.