この質問に対する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');
}
}