This patch adds a working beta version of an image field to the profile module. Admin can add image fields to the user profile in the same way other fields are added. Uploaded images are saved in the files directory. This is a working version but there is much room for improvement.
TODOs include:
-- add admin customization for image size. Admin should be able to specify maximum filesize and/or dimensions.
-- Code needs to be evaluated for conciseness and quality.
-- Display of images in the edit and profile views can be improved.
-- method _get_height_width_attributes($image_path) potentially has an equivalent in another method, and if not should possibly be moved to a module/inc where it makes more sense.
My intended use for the patch is to offer users a way to upload images to add styles to their personal blogs. I am offering a field where they can input CSS styles that get written into the header. Now they can upload images to use as background images or logos for their personal blogs.
The patch includes a couple of changes that should be refactored into another patch, which I will do in the next week. I didn't have time to do this today but I wanted to make the patch available for comments and evaluation. The changes referenced are the following:
in profile_form_profile I added t() calls to the titles of all fields.
in profile_validate_profile I changed the input parameter $edit to &$edit and added
if(!$edit){
$edit = array();
}becuase edit is initially NULL when uploading a file. If the validation fails (wrong file extension, for example), edit is returned NULL which causes an error in user.module.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | profile_module_image_patch_0.txt | 6.19 KB | robertdouglass |
| profile_module_image_patch.txt | 6.63 KB | robertdouglass |
Comments
Comment #1
(not verified) commentedThe 4.5 release is in a bugfix-only stage of development... this issue should be set to CVS.
I feel that this feature would be MUCH better suited as a contributed module than an addition to profile.module in core. This sort of functionality should probably also include the ability for administrators to view, at a glance, all users' images and view/delete them selectively. (That is, without manually navigating to each's user's page.)
Take a look at the use of the _user hook... it can be used to implement this in a way that would look identical to users. This would also have the advantage of moving the administration off the profile screen, so you could add a table of contributed images easily.
Also, for core, we avoid the use of tabs in the code, and private functions are preceded with their module name -- _get_height_width_attributes should be _profile_get_height_width_attributes.
-1 as part of core, but I'd really still like to see it as a contrib module.
Comment #2
robertdouglass commentedThanks for the suggestions - I'll clean the code up as indicated and resubmit the patch. I'll have to investigate making it a contrib module. Nothing against the idea, but if I run into hurdles implementing it I'll probably decide just to maintain my own profile.module branch (only a matter of not enough free-time and too many pressing projects :-)
Comment #3
robertdouglass commentedRemoved tabs and renamed private method as suggested.
Comment #4
killes@www.drop.org commentedThe patch contains hardcoded tables.
The patch should use image.inc functions (if applicable).
The whole functionality should be implemented as a contrib module.
Comment #5
marklein commentedThis patch is ok for drupal 6?
Thnak you!