Hey,
My case is that I have a content type called profile_pic. I want users to be able to upload pics to a profile gallery, so I was thinking maybe there is a way to add an if statement where if a "do you want this to be your avatar?" checkbox is checked, then the avatar gets updated.
I assume this also means another db query so that if a user checks this box, the database would have to be updated so that no other node of this type by this user has it checked.
And also I suppose to disable the checkbox if this is the first time a user has created a node of this type...
To clarify:
1. If this is the first time a user create a "profile_pic" node - Checkbox is diabled and this image becomes user's avatar.
2. If user creates another "profile_pic" node and DOESN'T check the box, avatar does not update
3. If user creates another or UPDATES "profile_pic" node and DOES check the box, avatar updates to node's image field, and database gets updated so that no other "profile_pic" nodes by this user has the checkbox still set.
I'm still learning the drupal api and so far everything I tried to do was documented perfectly, but I'm struggling on how to do this in a drupali way. If anyone here can point me in the right direction or can think of a better way of achieving what I need, that would be very helpful!
Thanks!
Comments
Comment #1
gorgo commentedUPDATE
I managed to fix this with a custom module for my site.
Not closing this cause I'm not sure if the maintainer of this module wants to leave it as an open feature request or not.
Comment #2
bluecobalt commentedHey gorgo,
Would you be willing to share your custom module? This is a very useful feature.
thanks,
Blue
Comment #3
gorgo commentedSure Blue!
Actually if you use a custom module, you can disable this one.
Just create a content type with an image field and a checkbox, and a custom module with this code:
You need to change MODULENAME to your module's name, CONTENT_TYPE(where in caps) to the name of your content type, field_CHECKBOX to the name of your checkbox field and field_IMAGE to the name of your image field.
Hope this helps. I have additional conditions and functionality in mine and had to rewrite it for you, so it's untested, but this should work.
Comment #4
gorgo commentedI should also mention that the checkbox field should be an integer with 1 as the value for 'Set as profile pic (or however you wanna label it)'.
Comment #5
hongpong commentedneat subscribe