Господа!
Встала задача, что бы при редактировании своих данных пользователем форма замены фотографии находилась в отдельной вкладке наподобие как к примеру выводятся дополнительные поля из модуля Profile. В результате всех стараний получилось следующее:
// $Id$
function picture_profile_menu ($may_cache) {
global $user;
$admin_access = user_access('administer users');
$items = array();
if (!$may_cache) {
$items[] = array('path' => 'user/'. arg(1) .'/edit/pictures', 'title' => t('Edit picture'),
'callback' => 'drupal_get_form', 'callback arguments' => array('picture_profile_edit'),
'access' => $admin_access || $user->uid == arg(1), 'type' => MENU_LOCAL_TASK);
}
return $items;
}
function picture_profile_form_alter($form_id, &$form) {
switch ($form_id) {
case 'user_edit' :
unset($form['picture']);
unset($form['comment_settings']);
unset($form['theme_select']);
break;
case 'picture_profile_edit' :
unset($form['comment_settings']);
unset($form['theme_select']);
break;
};
}
function _picture_profile_edit_form($uid, $edit, $register = FALSE) {
$admin = user_access('administer users');
if (variable_get('user_pictures', 0) && !$register) {
$form['picture'] = array('#type' => 'fieldset', '#title' => t('Picture'), '#weight' => 1);
$picture = theme('user_picture', (object)$edit);
if ($picture) {
$form['picture']['current_picture'] = array('#value' => $picture);
$form['picture']['picture_delete'] = array('#type' => 'checkbox', '#title' => t('Delete picture'), '#description' => t('Check this box to delete your current picture.'));
}
else {
$form['picture']['picture_delete'] = array('#type' => 'hidden');
}
$form['picture']['picture_upload'] = array('#type' => 'file', '#title' => t('Upload picture'), '#size' => 48, '#description' => t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
}
return $form;
}
function picture_profile_edit($category = 'account') {
global $user;
$account = user_load(array('uid' => arg(1)));
if ($account === FALSE) {
drupal_set_message(t('The account does not exist or has already been deleted.'));
drupal_goto('admin/user/user');
}
$edit = $_POST['op'] ? $_POST : (array)$account;
$form = _picture_profile_edit_form($account->uid, $edit);
$form['_category'] = array('#type' => 'value', '#value' => $category);
$form['_account'] = array('#type' => 'value', '#value' => $account);
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'), '#weight' => 30);
$form['#attributes']['enctype'] = 'multipart/form-data';
drupal_set_title(check_plain($account->name));
return $form;
}
function picture_profile_edit_validate($uid, &$edit) {
$user = user_load(array('uid' => $uid));
// If required, validate the uploaded picture.
if ($file = file_check_upload('picture_upload')) {
picture_profile_validate_picture($file, $edit, $user);
}
}
function picture_profile_validate_picture($file, &$edit, $user) {
global $form_values;
// Initialize the picture:
$form_values['picture'] = $user->picture;
// Check that uploaded file is an image, with a maximum file size
// and maximum height/width.
$info = image_get_info($file->filepath);
list($maxwidth, $maxheight) = explode('x', variable_get('user_picture_dimensions', '85x85'));
if (!$info || !$info['extension']) {
form_set_error('picture_upload', t('The uploaded file was not an image.'));
}
else if (image_get_toolkit()) {
image_scale($file->filepath, $file->filepath, $maxwidth, $maxheight);
}
else if (filesize($file->filepath) > (variable_get('user_picture_file_size', '30') * 1000)) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum file size is %size kB.', array('%size' => variable_get('user_picture_file_size', '30'))));
}
else if ($info['width'] > $maxwidth || $info['height'] > $maxheight) {
form_set_error('picture_upload', t('The uploaded image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'))));
}
if (!form_get_errors()) {
if ($file = file_save_upload('picture_upload', variable_get('user_picture_path', 'pictures') .'/picture-'. arg(1) .'.'. $info['extension'], 1)) {
$form_values['picture'] = $file->filepath;
}
else {
form_set_error('picture_upload', t("Failed to upload the picture image; the %directory directory doesn't exist or is not writable.", array('%directory' => variable_get('user_picture_path', 'pictures'))));
}
}
}
function picture_profile_edit_submit($form_id, $form_values) {
$account = $form_values['_account'];
$category = $form_values['_category'];
unset($form_values['_account'], $form_values['op'], $form_values['submit'], $form_values['delete'], $form_values['form_token'], $form_values['form_id'], $form_values['_category']);
user_module_invoke('submit', $form_values, $account, $category);
user_save($account, $form_values, $category);
// Delete that user's menu cache:
cache_clear_all($account->uid .':', 'cache_menu', TRUE);
// Clear the page cache because pages can contain usernames and/or profile information:
cache_clear_all();
drupal_set_message(t('The changes have been saved.'));
return 'user/'. $account->uid;
}
Но вот эта дополнительная вкладка выводиться только если включен модуль profile и есть дополнительные созданные им поля.
А как сделать что бы все работало и без этого модуля уже мозгов не хватает...парюсь третий день.
Может у кого есть светлые мысли по этому вопросу?
В качестве бонуса за реальную помощь могу предложить модуль выводящий на одной странице блоки авторизации/регистрации.