Skip to content

Commit

Permalink
Add profile form fields to user registration page. Processing of thes…
Browse files Browse the repository at this point in the history
…e values isn't happening yet.
  • Loading branch information
torrance committed May 25, 2014
1 parent db0ccfd commit cbc32ef
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions civicrm.module
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,34 @@ function _civicrm_get_profiles($contact_id) {
}
}
return $profiles;
}

/**
* Implements hook_form_TAG_ID_alter().
*
* Attach any relevant profile form fields to user registration form.
*/
function civicrm_form_user_register_form_alter(&$form, &$form_state, $form_id) {
$civicrm = \Drupal::service('civicrm');
$html = \CRM_Core_BAO_UFGroup::getEditHTML(NULL, '', 1, TRUE, FALSE, NULL, FALSE, $civicrm->getCtype());

$form['civicrm_profile_register'] = array(
'#markup' => $html,
);
$form['#validate'][] = '_civicrm_user_register_form_validate';
}

/**
* Validation function for additional profile form fields attached to user registration form.
*/
function _civicrm_user_register_form_validate(&$form, &$form_state) {
\Drupal::service('civicrm');
$errors = CRM_Core_BAO_UFGroup::isValid(NULL, '', TRUE);

if (is_array($errors)) {
$form_builder = \Drupal::formBuilder();
foreach ($errors as $name => $message) {
$form_builder->setErrorByName($name, $form_state, $message);
}
}
}

0 comments on commit cbc32ef

Please sign in to comment.