Update the author_uid for an entity registration I'm looking to update the author_uid for an Entity Registration in Drupal 7 programatically. I want to replace all anonymous users with the UID of 0 with another UID lets say 2 upon saving the registration. I have tried three different solutions thus far to no avail. 

Solution 1) Update the author_uid in the $form_state prior to saving the registration form.

&lt;?php
function registration_form_alterations_form_alter(&amp;$form, &amp;$form_state, $form_id) {

    if ($form_id == "registration_form") {
        dpm($form);
        dpm($form_state);
        $form['#submit'][] = 'registration_form_alterations_custom_submit';

    }
}

function registration_form_alterations_custom_submit($form, &amp;$form_state) {
    //  submit handler code
    dpm($form_state);
}


This didn't work because author_uid isn't available to be altered in form_state to the best of my knowledge.

Solution 2) Update via hook_entity_presave. I'm not sure this will work because I can't seem to isolate the actual registration entity to update the author_id in hook_entity_presave. 

Solution 3) Use rules... Which doens't allow you to update the author_uid. A rules message screen comes back with a message about the value not being writable/editable.

Does anyone have any additional thoughts on this. Sorry I know its a bit of a weird request, but we have a user that wants anonymous registrations reassigned to them so that they can manage additional details associated with the registrations.
(a) hook_entity_presave() should work, giving you access to the entity, before it is persisted, e.g.:

/**
 * Implements hook_entity_presave().
 */
function registration_alterations_entity_presave($entity, $type) {
  if ($type === 'registration' &amp;&amp; $entity-&gt;author_uid === 0)) {
    $entity-&gt;author_uid = variable_get('registration_alterations_anonymous_registrations_reassign_uid');
  }
}


(b) Alternatively, you could use hook_field_attach_submit(), which is also triggered inside registration_form_submit() and would give you access to the submitted form in case you needed it. This would look similar to (a):

/**
 * Implements hook_field_attach_submit().
 */
function registration_alterations_field_attach_submit($entity_type, $entity, $form, &amp;$form_state) {
  if ($entity_type === 'registration' &amp;&amp; $entity-&gt;author_uid === 0)) {
    $entity-&gt;author_uid = variable_get('registration_alterations_anonymous_registrations_reassign_uid');
  }
}


Good luck!