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.
<?php
function registration_form_alterations_form_alter(&$form, &$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, &$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.