How to make a user choose male or female and keep a default image on a specific content? How can I make a user choose male or female and keep a default image on a specific content?

I mean I want two defaults pictures (for male and female), but only for default image in case user want to upload a different image this should be accept as normal.

And all this for one specific type of content.

I want this, just because this field must captures a photo but for the ones who don't want to upload a photo show a default profile image.
You can do this on the display level via


hook_preprocess_field() (thx Clive in the comments, give him a thumbs up!), OR
a custom formatter, OR
a custom Display suite field


hook_preprocess_field() on the image field is the easiest.

You have the full user entity available and can use information from other fields to alter the image.

The hook is fired every time theme('field', ..) is fired, so you need to figure out if this is the correct field.

EDIT: Instead of a detailed tutorial, here is what I usually do:


Install devel
Create your custom module with an implementation of hook_preprocess_field(&amp;$variables).
Do dpm($variables) inside that hook implementation to show the function argument (sometimes you need to refresh the page twice to see the result).
Manipulate the part of $variables that you are interested in.


With a custom formatter, you can define your own way to display e.g. the image field, while having the data from other node fields available.

Then on the user display configuration, you can choose this formatter to display the image.

With the custom DS field, you can introduce a "field" - that is, a positionable element on the entity display. This field can use data from multiple data fields on the node entity. E.g. you first check if there is an explicitly uploaded image, and if not, you show an image depending on the gender (male, female, transgender / don't say).

You can also define a form to configure display options. E.g. you could make the image style configurable.

Steps:


Enable Display suite
Implement hook_ds_fields_info() in a custom module, using e.g. DS_FIELD_TYPE_FUNCTION.
Provide the function to generate the html or render array (some examples)
Configure your user to display with a Display suite layout.
Enable your custom field.


There are more details to this. But I the main purpose of this answer is to point you in a direction.



The weakness of all these options is that you have to hardcode the field names, or at least one of them. If you want to reuse this on another site with other field names, you have to change the field names in the code.