1 user.pages.inc | user_profile_form($form, &$form_state, $account) |
Form builder; edit a user account.
See also
user_cancel_confirm_form_submit()
Related topics
File
- core/
modules/ user/ user.pages.inc, line 339 - User page callback file for the user module.
Code
function user_profile_form($form, &$form_state, $account) {
global $user;
// During initial form build, add the entity to the form state for use during
// form building and processing. During a rebuild, use what is in the form
// state.
if (!isset($form_state['user'])) {
$form_state['user'] = $account;
}
else {
$account = $form_state['user'];
}
// @todo Legacy support. Modules are encouraged to access the entity using
// $form_state.
$form['#user'] = $account;
user_account_form($form, $form_state);
// Attach field widgets.
field_attach_form('user', $account, $form, $form_state);
// Prepare cancel link.
if (isset($_GET['destination'])) {
$path = $_GET['destination'];
}
elseif (isset($_SERVER['HTTP_REFERER'])) {
$path = $_SERVER['HTTP_REFERER'];
}
elseif (isset($account->uid)) {
$path = 'user/' . $account->uid;
}
else {
$path = '<front>';
}
$options = backdrop_parse_url($path);
$options['attributes']['class'][] = 'form-cancel';
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['actions']['cancel'] = array(
'#type' => 'submit',
'#value' => t('Cancel account'),
'#submit' => array('user_edit_cancel_submit'),
'#access' => $account->uid > 1 && (($account->uid == $user->uid && user_access('cancel account')) || user_access('administer users')),
);
$form['actions']['cancel_form'] = array(
'#type' => 'link',
'#title' => t('Cancel'),
'#href' => $options['path'],
'#options' => $options,
'#weight' => 1,
);
$form['#validate'][] = 'user_profile_form_validate';
// Add the final user profile form submit handler.
$form['#submit'][] = 'user_profile_form_submit';
return $form;
}