function invite_user_presave in Invite 8
Same name and namespace in other branches
- 7.4 invite.module \invite_user_presave()
- 7.2 invite.module \invite_user_presave()
Implements hook_user_presave().
File
- ./
invite.module, line 16 - Default file for Invite Project.
Code
function invite_user_presave(User $account) {
if (!empty($_SESSION['invite_code'])) {
// Update invite when user accepts.
$id = Drupal::entityQuery('invite')
->condition('reg_code', $_SESSION['invite_code'])
->execute();
$invite = Invite::load(reset($id));
$invite
->setJoined(\Drupal::time()
->getRequestTime());
$invite
->setStatus(InviteConstants::INVITE_USED);
$invite
->save();
// Add target role to user.
$data = unserialize(\Drupal::config('invite.invite_type.' . $invite
->get('type')->value)
->get('data'));
if ($data['target_role'] != '0') {
$account
->addRole($data['target_role']);
}
$account
->activate();
}
}