function redhen_contact_user_registration_submit in RedHen CRM 7
Same name and namespace in other branches
- 8 modules/redhen_contact/redhen_contact.module \redhen_contact_user_registration_submit()
Registration form RedHen contact submit handler.
Creates a Contact on user registration.
Parameters
array $form: Form array.
array $form_state: Form state array.
1 string reference to 'redhen_contact_user_registration_submit'
- redhen_contact_form_user_register_form_alter in modules/
redhen_contact/ redhen_contact.module - Implements hook_form_FORM_ID_alter().
File
- modules/
redhen_contact/ redhen_contact.module, line 1314 - Module file for RedHen contacts.
Code
function redhen_contact_user_registration_submit($form, &$form_state) {
$contact = $form_state['redhen_contact'];
$uid = $form_state['user']->uid;
// Does a contact already exist with that email address?
$existing_contact = redhen_contact_load_by_mail($form_state['values']['mail']);
$contact = $existing_contact ? current($existing_contact) : $contact;
// Set user.
$contact->uid = $uid;
// If set to update fields, do so.
if (variable_get(REDHEN_CONTACT_REG_UPDATE_FIELDS, FALSE) == TRUE || !empty($contact->is_new)) {
$contact->author_uid = $uid;
$message_update = _redhen_contact_user_submission_apply($form, $form_state, $contact, TRUE);
// Set email address.
redhen_contact_property_email_set($contact, NULL, $form_state['values']['mail']);
}
redhen_contact_save($contact);
$message = t('User has been linked to the contact %name.', array(
'%name' => $contact
->label(),
));
if (isset($message_update)) {
$message .= ' ' . $message_update;
}
// Update form_state contact for later processing.
$form_state['redhen_contact'] = $contact;
// Only display this message to CRM users to avoid confusion.
if (user_access('access redhen contacts')) {
drupal_set_message($message);
}
}