By mariusooms on
Hi, I need help porting some custom code to Drupal 6. The goal of this code is to move the "User picture upload interface" to its own tab on the Account edit page. It currently fails at validation and removing the original Upload Picture interface. I've tried my hardest and could get it to work, but I have limited understanding of the internals. Code provided by Josh Koenig from chapterthree.com
<?php
function avatar_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'categories') {
$categories = array(array(
'name' => 'avatar',
'title' => t('User picture'),
'weight' => 1)
);
return $categories;
}
if ($op == 'form' && $category == 'avatar') {
$form = array();
$form['avatar'] = array(
'#type' => 'fieldset',
);
$form['avatar']['preview'] = array(
'#type' => 'markup',
'#value' => theme('user_picture', $account),
'#prefix' => '<h2>'. t('Your current picture'). '</h2>',
);
$form['avatar']['picture_upload'] = array(
'#type' => 'file',
'#title' => t('Upload a new picture'),
'#size' => 20,
);
return $form;
}
if ($op == 'validate' && $category == 'avatar') {
if ($file = file_check_upload('picture_upload')) {
// user.module's function for validating pictures is plenty good
user_validate_picture($file, $edit, $account);
}
}
}
function avatar_form_alter($form_id, &$form) {
if($form_id == 'user_edit' && arg(3) == NULL) {
// only fire this if it's user/<uid>/edit, not any other category
unset($form['picture']);
}
}
?>
Comments
I meant to say, "I've tried
I meant to say, "I've tried my hardest and could NOT get it to work", sorry for the typo.
Kind regards,
Marius
Marius Hi, Did you find a
Marius Hi,
Did you find a solution to move the user picture to it's own tab? That would be wonderful, thanx!
nope....sorry...I just change
nope....sorry...I just change the weight in core (shhh, don't tell anyone) so that it is the first item in settings and live with it.
Regards,
Marius
The form id =
The form id = user_profile_form
On another page
I managed to get it on another page. You could change the menu callbacks to make it a tab. Did it this way:
1. create your module file and its .info file
2. in your module, first write a hook_menu to point to you page like so:
3. write your function to grab the form from the user module:
On second thoughts
Ran into a few issues with this implementation. Though it work well initially, but had problems with imagecache etc. A deeper look into the user module and I came up with a few changes:
Change Step 2:
This create an url that calls the original user edit page with an additional argument
Change Step 3:
Call a form alter for the particular url
can you share
Can you share your .module file, am trying to create a page which has only upload picture feature using your above said code, but when I go to page user/uid/edit/account/upload-picture i get a 'page not found' error.
Did you flush the cache?
Did you flush the cache?
yes I did flush the cache, i
yes I did flush the cache, i am putting my .module code below for your review, please correct if I am doing anything wrong.
<?php
function userpictureupload_menu(){
$items['user/%user/edit/account/upload-picture'] = array(
'title' => 'Upload Profile Picture',
'page callback' => 'user_edit',
'page arguments' => array(1),
'access callback' => 'user_edit_access',
'access arguments' => array(1),
'type' => MENU_CALLBACK,
'load arguments' => array('%map', '%index'),
'file' => 'user.pages.inc',
'file path' => drupal_get_path('module', 'user'),
);
}
function userpictureupload_form_alter(&$form, $form_state, $form_id){
if($form_id == 'user_profile_form' && arg(4) == 'upload-picture'){
//if changing username is disallowed, it will be hidden by default
$form['account']['pass']['#type'] = 'hidden';
$form['account']['#title'] = t('');
$form['account']['mail']['#type'] = 'hidden';
unset($form['contact']);
}
}
Thanks for your help, also to let you know I am using 'me' module
Thanks and regards
Hi, i am trying to put an
Hi,
i am trying to put an upload picture form in a block, but it behaves strangely...
I print it
print drupal_get_form("user_profile_form");clear the cache and it shows there but only once, if i reload the page it disappears when i print out the form variables there is something but not the fields.. any idea?
I would apreciate any help!
I tried creating a module as
I tried creating a module as per above, but nothing happens. (yes, I cleared the caches - still nothing)
From reading the code, it seems like you're unsetting all other elements on the Account Settings page. But what is needed is only moving the Picture Upload form to a separate tab.
Can someone PLEASE post the code for a module that works?
Avatar module for 6.x
Here is my own module code for 6.x (create a module called "Avatar" with its .info file and in avatar.module file paste this code)
Note: I use Avatar Crop module, so I deliberately commented out the default picture upload form/buttons. I also tried to get rid of the "Save" and "Delete" buttons because those come from 'user_profile_form' (the account settings form) and therefore are confusing and dangerous, but I couldn't do remove them. If you know how to remove the "Save" and "Delete" button from this tab, I would greately appreciate it.
If you know how to remove the "Save" and "Delete" buttons on this form, without removing them on the Account Settings page, please help and write your solution.
Drupal 6.15 working module
Buttons *Save|Delete* only for root account. Other user see only *Save*
With your module the
With your module the "Picture" tab didn't appear at all. In functions I changed "userpictureupload" to "avatar" and it worked. But the Save|Delete buttons still appear. This is dangerous if you allow users to delete their own accounts. (they'll be thinking that they are deleting only the picture, but in fact would be deleting their own accounts)
Has anyone done work on this problem for d7?
I'm looking for a start on a d7 solution.
For any user profile field in
For any user profile field in D7 I use this: