function profile2_regpath_attach_profile_fields in Profile2 Registration Path 7.2
Same name and namespace in other branches
- 7 profile2_regpath.inc \profile2_regpath_attach_profile_fields()
1 call to profile2_regpath_attach_profile_fields()
- profile2_regpath_form_alter in ./profile2_regpath.module
- Implements hook_form_alter().
File
- ./profile2_regpath.inc, line 11
- Modifications to the user registration form.
Code
function profile2_regpath_attach_profile_fields(&$form, &$form_state, $form_id, $profile_types = NULL) {
$menu_item = menu_get_item();
if (!$profile_types && ($menu_item['path'] == 'system/ajax' || $menu_item['path'] == 'file/ajax')) {
$url = drupal_parse_url($form['#action']);
$path = end(explode('/', str_replace('/register', '', $url['path'])));
$profile_types = profile2_regpath_regpath_load_multiple(array(
'path' => $path,
));
}
if ($profile_types != NULL) {
$user_roles = user_roles(TRUE);
$roles = array();
foreach ($profile_types as $type_name => $value) {
$profile_type = profile2_get_types($type_name);
if (empty($form_state['profiles'][$type_name])) {
$profile = profile_create(array(
'type' => $type_name,
));
$form_state['profiles'][$type_name] = $profile;
$misc = unserialize($profile_types[$type_name]->misc);
if ($misc['fieldset_wrap']) {
$form['profile_' . $type_name] = array(
'#type' => 'fieldset',
'#title' => check_plain($profile_type->label),
);
}
$form['profile_' . $type_name]['#weight'] = $profile_type->weight;
if (isset($misc['confirmation_display'])) {
$_SESSION['profile2_regpath']['confirmation_message'] = $misc['confirmation_message'];
}
}
$profile_roles = unserialize($value->roles);
foreach ($profile_roles as $rid => $value) {
if ($value != 0 && !array_key_exists($rid, $form['account']['roles'])) {
$form['account']['roles'][$rid] = array(
'#type' => 'checkbox',
'#title' => check_plain($user_roles[$rid]),
'#default_value' => TRUE,
'#disabled' => user_access('administer users') ? FALSE : TRUE,
);
}
}
}
profile2_attach_form($form, $form_state);
}
}