function party_user_user_insert in Party 7
Same name and namespace in other branches
- 8.2 modules/party_user/party_user.module \party_user_user_insert()
Implements hook_user_insert().
If we have set up Party Acquisition, perform a party match based off of the mail of the account being created. If it exists, this user will acquire the party, if not we'll create a party. We will also create a user if we don't use Party Acquisition but we have set that we want to create a party when a user registers.
File
- modules/
party_user/ party_user.module, line 318 - Support for linking users to parties
Code
function party_user_user_insert(&$edit, $account, $category) {
if ($category == 'account') {
// Don't acquire if the user has already been acquired.
if (!empty($account->party_attaching_party)) {
return;
}
// Find our what action to take.
$action = variable_get('party_user_on_registration', 'nothing');
if ($action == 'nothing') {
return;
}
// Set up our acquisition.
$values = array();
if ($action == 'acquire') {
$values['email'] = $account->mail;
}
// Clone our account.
$account_clone = clone $account;
unset($account_clone->is_new);
// Set up our context.
$context = array(
'name' => 'party_user_registration',
'account' => $account_clone,
'behavior' => PartyAcquisitionInterface::BEHAVIOR_CREATE,
'party_user' => array(
'has_user' => FALSE,
),
);
if (module_exists('party_hat')) {
// Make sure the party is allowed a user.
$context['party_hat']['data_set'] = array(
'user',
);
// Add in our hats.
$context['party_hat']['add'] = variable_get('party_user_registration_hats', array());
}
// Fire off our acquisition.
$party = party_acquire($values, $context, $method);
$party
->save();
// Attach our new user.
$party
->getDataSetController('user')
->attachEntity($account_clone)
->save();
// Trigger our acquisition hook and email sync.
module_invoke_all('party_user_acquisition', $party, $account_clone, $method);
party_user_email_sync($account_clone);
}
}