function profile2_regpath_form_alter in Profile2 Registration Path 7.2
Same name and namespace in other branches
- 7 profile2_regpath.module \profile2_regpath_form_alter()
Implements hook_form_alter().
File
- ./
profile2_regpath.module, line 154 - Attach profile2 form to registration form according to path.
Code
function profile2_regpath_form_alter(&$form, &$form_state, $form_id) {
$menu_item = menu_get_item();
// Check to see if we're building this form for a block.
if (strpos($form_id, 'profile2_regpath_form_block_') === 0) {
module_load_include('inc', 'profile2_regpath');
$profile_types = profile2_regpath_regpath_load_multiple(array(
'profile_type' => $form_state['profile_type'],
'status' => 1,
));
profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
}
elseif ($form_id == 'user_register_form') {
// Logintoboggan might display user_register_form on 403 pages.
if (module_exists('logintoboggan') && variable_get('site_403') == 'toboggan/denied' && strpos(drupal_get_http_header('Status'), '403') === 0) {
$profile_types = profile2_regpath_get_profiles('user');
}
else {
// Get profile2 profile types from current path.
$url = drupal_parse_url($form['#action']);
$path = ltrim($url['path'], '/');
// Check to see if this is an alias. If so, use source path.
if ($source = drupal_lookup_path('source', $path)) {
$path = $source;
}
// Grab first part of URL.
$path_parts = explode('/', $path);
$path_key = reset($path_parts);
// Load profiles for this path key.
$profile_types = profile2_regpath_regpath_load_multiple(array(
'path' => $path_key,
'status' => 1,
));
}
// Attach associated fields.
module_load_include('inc', 'profile2_regpath');
profile2_regpath_attach_profile_fields($form, $form_state, $form_id, $profile_types);
}
}