I’m having problems saving my custom entity to the db. I created a custom entity called ‘review’ using hook_entity_info()
with a custom controller. I have specified some parameters in the controller using:
public function create(array $values = array()) { global $user; $values = array( 'rid' => '', 'uid' => $user->uid, 'nid' => $_GET['nid'], 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, 'published' => 1, 'quality' => '', 'design' => '', 'versatility' => '', 'design' => '', ); return parent::create($values); }
Everything seems to be working just fine but when I try to submit my form to create a new entity not all fields are saved in the db.
I attached the value of the fields in the form using field_attach_form('review', $review, $form, $form_state);
and in my submit function I have this:
$review_submission = (object) $form_state['values']; field_attach_submit('review', $review_submission, $form, $form_state); $review = entity_create('review', array('type' => 'review')); $entity = entity_metadata_wrapper('review', $review); $entity->save($review_submission); //This saves info but not fields
This creates a new entity but the fields 'quality', 'design', 'versatility', 'relevance'
are not saved. However if I use this instead in my submit function:
review_submission = (object) $form_state['values']; field_attach_submit('review', $review_submission, $form, $form_state); $review = entity_create('review', array('type' => 'review')); $entity = entity_metadata_wrapper('review', $review); entity_get_controller('review')->save($review_submission); //This saves fields but not info
those fields are correctly saved BUT then 'rid', 'uid', 'nid', 'created', 'changed', 'published'
are not saved.
What am I missing? How can I saved the entity info and the values from the form fields?