Commit 31e791b9 authored by Dries's avatar Dries

- Patch #109588 by fago, cdale: make hook_user use instead of arg(1).

parent 1c0f4ac3
......@@ -674,7 +674,7 @@ function user_user_view(&$edit, &$account, $category = NULL) {
function user_user_form(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
$form_state = array();
return user_edit_form($form_state, arg(1), $edit);
return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit);
}
}
......@@ -683,7 +683,7 @@ function user_user_form(&$edit, &$account, $category = NULL) {
*/
function user_user_validate(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
return _user_edit_validate(arg(1), $edit);
return _user_edit_validate($account, $edit);
}
}
......@@ -692,7 +692,7 @@ function user_user_validate(&$edit, &$account, $category = NULL) {
*/
function user_user_submit(&$edit, &$account, $category = NULL) {
if ($category == 'account') {
return _user_edit_submit(arg(1), $edit);
return _user_edit_submit($account, $edit);
}
}
......@@ -1458,7 +1458,8 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
'#title' => t('Account information'),
'#weight' => -10,
);
if (user_access('change own username') || $admin || $register) {
// Only show name field when: registration page; or user is editing own account and can change username; or an admin user.
if ($register || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || $admin) {
$form['account']['name'] = array('#type' => 'textfield',
'#title' => t('Username'),
'#default_value' => $edit['name'],
......@@ -1559,10 +1560,10 @@ function user_edit_form(&$form_state, $uid, $edit, $register = FALSE) {
return $form;
}
function _user_edit_validate($uid, &$edit) {
$user = user_load(array('uid' => $uid));
// Validate the username:
if (user_access('change own username') || user_access('administer users') || !$user->uid) {
function _user_edit_validate($account, &$edit) {
$uid = isset($account->uid) ? $account->uid : FALSE;
// Validate the username when: new user account; or user is editing own account and can change username; or an admin user.
if (!$uid || ($GLOBALS['user']->uid == $uid && user_access('change own username')) || user_access('administer users')) {
if ($error = user_validate_name($edit['name'])) {
form_set_error('name', $error);
}
......@@ -1580,12 +1581,11 @@ function _user_edit_validate($uid, &$edit) {
}
}
function _user_edit_submit($uid, &$edit) {
$user = user_load(array('uid' => $uid));
function _user_edit_submit($account, &$edit) {
// Delete picture if requested, and if no replacement picture was given.
if (!empty($edit['picture_delete'])) {
if ($user->picture && file_exists($user->picture)) {
file_unmanaged_delete($user->picture);
if ($account->picture && file_exists($account->picture)) {
file_unmanaged_delete($account->picture);
}
$edit['picture'] = '';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment