function onepageprofile_user in One page profile 6
Same name and namespace in other branches
- 5.2 onepageprofile.module \onepageprofile_user()
Implementation of hook_user().
Here we rebuild the user's account edit form by adding all the other categories. As we are bypassing the security at the menu layer, we need to make sure user has permission to do all these things.
File
- ./
onepageprofile.module, line 62
Code
function onepageprofile_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
if ($category == 'account') {
$form = array();
// profile module
$categories = profile_categories();
foreach ($categories as $category) {
if (_onepageprofile_check_access($account, $category)) {
$category_name = $category['name'];
$category_form = profile_form_profile($edit, $account, $category_name, FALSE);
// Add translation support
// http://drupal.org/node/694590
if (module_exists('i18nprofile')) {
i18nprofile_form_translate_category($category_form, $category_name);
}
// Prevent errors with other modules which expect an #id
// http://drupal.org/node/901444
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
);
$category_form['#id'] = 'profile_form_profile';
$category_form['#parameters'] = array(
'profile_form_profile',
$edit,
$account,
$category_name,
FALSE,
);
// See comments in drupal_alter in includes/common.inc
// http://drupal.org/node/901444
$data =& $category_form;
$data['__drupal_alter_by_ref'] = array(
&$form_state,
);
drupal_alter('form', $data, 'profile_form_profile');
$form += $category_form;
}
}
// simplenews module
if (module_exists('simplenews')) {
$simplenews_form = simplenews_user('form', $edit, $account, 'newsletter');
if (is_array($simplenews_form)) {
$form += $simplenews_form;
// Simplenews wipes out the #submit handler
// http://drupal.org/node/1269104
if (isset($form['#submit']) && is_array($form['#submit']) && array_search('user_profile_form_submit', $form['#submit']) === FALSE) {
$form['#submit'][] = 'user_profile_form_submit';
}
}
}
return $form;
}
break;
case 'update':
// We need to call profile_save_profile because the profile module expects
// $category to be set to the profile field group. With onepageprofile, this
// is no longer the case.
//
// Ensure we're on the account edit page:
// - form_build_id ensures this is not called programatically
// - $category === 'account' ensures we're not on a module provided category page.
if (isset($edit['form_build_id']) && $category === 'account') {
// profile module
$categories = profile_categories();
foreach ($categories as $category) {
profile_save_profile($edit, $account, $category['name']);
}
// simplenews module
if (module_exists('simplenews')) {
simplenews_user('update', $edit, $account, 'newsletter');
}
}
break;
}
}