基于zhilevan对这个问题和这个问题的答案以及对drupal.org的讨论,这是对我有用的实际代码:
function MYMODULE_menu() {
$items = array();
$items['user/editpurposes'] = array(
'title' => t('Change your purposes'),
'page callback' => 'MYMODULE_purpose_edit_form',
'access callback' => TRUE,
'access arguments' => array('access content'),
'description' => t('Purpose Edit Form'),
'type' => MENU_CALLBACK,
);
return $items;
}
function MYMODULE_purpose_edit_form() {
// Needed to load AJAX.
module_load_include('inc', 'user', 'user.pages');
global $user;
$account = user_load($user->uid); // Load a user object
$form = drupal_get_form('user_profile_form', $account, 'account', 'purposes');
return $form;
}
function MYMODULE_form_user_profile_form_alter(&$form, &$form_state) {
if(isset($form_state['build_info']['args'][2]) && $form_state['build_info']['args'][2] == 'purposes') {
// Remove name, email, password, etc.
$form['account']['#access'] = FALSE;
// Remove language.
$form['locale']['#access'] = FALSE;
$form['timezone']['#access'] = FALSE;
// Remove various custom fields.
$form['field_acc_displayname']['#access'] = FALSE;
$form['field_acc_code_agree']['#access'] = FALSE;
// Needed to load AJAX.
form_load_include($form_state, 'inc', 'user', 'user.pages');
}
}