Saving form fields on custom entity 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' =&gt; '',
      'uid' =&gt; $user-&gt;uid,
      'nid' =&gt; $_GET['nid'],
      'created' =&gt; REQUEST_TIME,
      'changed' =&gt; REQUEST_TIME,
      'published' =&gt; 1,
      'quality' =&gt; '',
      'design' =&gt; '',
      'versatility' =&gt; '',
      'design' =&gt; '',
   );
   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' =&gt; 'review'));
$entity = entity_metadata_wrapper('review',  $review);
$entity-&gt;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' =&gt; 'review'));
$entity = entity_metadata_wrapper('review',  $review);
entity_get_controller('review')-&gt;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?
As far as I understand, you need to provide these values manually before the save, for example:

$entity-&gt;created = isset($entity-&gt;is_new) ? REQUEST_TIME : $entity-&gt;created;
$entity-&gt;changed = REQUEST_TIME;
$entity-&gt;uid = $user-&gt;uid;


or copy them directly from $form_state['values'].

I've found entityFormSubmit method from Inline Entity Form module which is manually copying all fields which are not fields to entity properties, so gave me the idea for this code:

$form_id = $form_state['build_info']['form_id'];
$entity = $form['#entity'] ?: $form_state['build_info']['args'][0];
$entity_type = $entity-&gt;entityType();
$entity_info = entity_get_info($entity_type);
$entity_values = drupal_array_get_nested_value($form_state['values'], $form['#parents']);
list(, , $bundle) = entity_extract_ids($entity_type, $entity);

$values_excluding_fields = $info['fieldable'] ? array_diff_key($entity_values, field_info_instances($this-&gt;entityType, $bundle)) : $entity_values;
foreach ($values_excluding_fields as $key =&gt; $value) {
  $entity-&gt;$key = $value;
} 
if ($entity_info['fieldable']) {
  field_attach_submit($entity_type, $entity, $form, $form_state);
}
$entity-&gt;created = isset($entity-&gt;is_new) ? REQUEST_TIME : $entity-&gt;created;
$entity-&gt;changed = REQUEST_TIME;
entity_save($entity_type, $entity);