I use the node registration module to register users to events.
I want even anonymous users to register (and thus changing the drupal permissions I can do this).
I created a rule that "for each saved registration node" creates a user type entity.
But I can not contextually create the node registration and create the user to edit the fields in the node_registration uid and author_uid table going to insert the uid of the newly created user.

So I find myself a user with username username@mail.com,
a node registration with the mail username@mail.com

and I can not bind them together because the row in the node_registration table is uid = 0 author_uid = 0

I managed to solve by scheduling a component that makes the update_query on the database, but it does not seem to me the correct way

Did you have the same problem?

Comments

lucavox created an issue. See original summary.

lucavox’s picture

Issue summary: View changes
rudiedirkx’s picture

You're creating users from anonymous registrations..? Kewl.

I don't know Rules very well... It's probably much easier with custom code. You can use the node registration 'presave' hook to make a user AND update the registration's uid.

I don't know how to Rules it. Maybe ask on drupal SE or in a Drupal group?

lucavox’s picture

thanks! rudiedirkx
can you tell me the context of this hook?
verifying in node_registration.api.php I find
* Implements hook_node_registration_presave ().
  * /
function hook_node_registration_presave ($ registration) {

}

but it would seem that I can not intercept

* Implements hook_node_registration_presave ().
  * /
function hook_node_registration_presave ($ registration) {
dpm ($ registration);
}

rudiedirkx’s picture

Intercept? You want the registration to be created, and a user, right?

So create the user in that hook using the registration data in $registration, and then put the new uid in $registration->uid.

The context is the registration... I don't know what you mean. It's called just before saving the registration into the db, so you can't stop it anymore, but you can alter its values before it's inserted.

Don't forget to check if it's a new registration, not an existing:

if (empty($registration->registration_id))

Does that help?

rudiedirkx’s picture

Ah, now I get it. You didn't rename the function. The hook_ prefix is a Drupal api standard, but not what the function should be called. You have to create a module, let's say abc_def and then rename the hook function: 'hook' becomes the module machine name, so the function ne becomes abc_def_node_registration_presave

Did that help?

lucavox’s picture

#6
It was very useful and I thank you!
but now, unfortunately, another problem has arisen!

function registrazioni_node_registration_presave($registration) {
if ($registration->uid == 0) {
$new_user = array(
  'name' => 'JohnDoe',
  'mail' => $registration->email,
  'pass' => 'password123',
  'status' => 1,
  'field_custom_first_name' => array(LANGUAGE_NONE => array(array('value' => 'John'))), // This becomes $account->field_custom_first_name[LANGUAGE_NONE][0]['value']
  'field_custom_last_name' => array(LANGUAGE_NONE => array(array('value' => 'Doe'))),
  'access' => REQUEST_TIME,
  'roles' => array(), // No other roles than Authenticated
  //'roles' => array('10' => '10', '11' => '11'), // If you want to specify additional roles, the numbers are role_id's
);
$accountb = user_load_by_mail($registration->email);
$uidn = $accountb->uid;
$registration = array(
  'uid' => $uidn,
  'author_uid' => $uidn,
);
user_save(NULL, $new_user);
dpm($registration);
}

When I create a user in presave, then I do not validate the node registration from anonymous because it tells me that there is already a mail like that of node registration