function profile2_regpath_attach_profile_fields in Profile2 Registration Path 7
Same name and namespace in other branches
- 7.2 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
- Contains logic for modifying user registration forms.
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 = explode('/', str_replace('/register', '', $url['path']));
$path_key = end($path);
$profile_types = profile2_regpath_regpath_load_multiple(array(
'path' => $path_key,
));
}
if ($profile_types != NULL) {
$user_roles = user_roles(TRUE);
foreach ($profile_types as $key => $value) {
$type_name = (string) $profile_types[$key]->profile_type;
$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[$key]->misc);
if ($misc['fieldset_wrap']) {
$form['profile_' . $type_name] = array(
'#type' => 'fieldset',
'#title' => check_plain(profile2_regpath_get_profile_label($profile_types[$key]->profile_type)),
);
}
$form['profile_' . $type_name]['#weight'] = $profile_type->weight;
if (!empty($misc['confirmation_display'])) {
$_SESSION['profile2_regpath']['confirmation_message'] = filter_xss($misc['confirmation_message']);
}
}
$profile_roles = unserialize($value->roles);
foreach ($profile_roles as $rid => $role_name) {
if (!empty($role_name) && !array_key_exists($rid, $form['account']['roles']) && isset($user_roles[$rid])) {
$form['account']['roles'][$rid] = array(
'#type' => 'checkbox',
'#title' => check_plain($user_roles[$rid]),
'#default_value' => TRUE,
'#disabled' => !user_access('administer users'),
);
}
}
}
profile2_attach_form($form, $form_state);
}
}