It seems that this feature is available for Drupal 6, but not for 7, or am I missing something?

Comments

BParticle’s picture

I'm looking for that option too, any answers?

avelens’s picture

At: /admin/config/people/accounts you can find the option to choose picture or not.

skizzo’s picture

In Avatar Selection 7.x-1.0 I see the "Force users to select an avatar image on user registration" checkbox in admin/config/people/avatar_selection, and it's working for me (please make sure that "access avatars" is checked for Anonymous User in admin/people/permissions, and that few avatars have been loaded in admin/config/people/avatar_selection/upload. @pieter_degraeuwe: could you please confirm that the same still applies for 7.x-1.x-dev?

vali hutchison’s picture

Hi Skizzo,

Looks like you're posting to the wrong issue list here - this is the issue list for the register with picture module - looks like this needs to be in the avatar selection module issue list - http://drupal.org/project/issues/avatar_selection ?

skizzo’s picture

you are absolutely right! Sorry...
I was "following" a wrong issue.
Thank you.

dlinhle’s picture

I can see the option to enable pictures on registration at /admin/config/people/accounts ... but I can't see the option to make it a required input for registration. Does this exist and, if so, where is it?

barnettech’s picture

Yes I have the same problem. I looked through the code and don't see any mention of the word 'required'

I just added '#required' => 1, to line 55 of reg_with_pic.module and this made the field required.

Would you mind adding this to you code? I could make an official patch if you like, but it's only one line.

To be clear this is what it needs to look like:

// Set picture file field.
 51   $form['picture']['picture_upload'] = array(
 52     '#type' => 'file',
 53     '#title' => t('Upload picture'),
 54     '#size' => 48,
 55     '#required' => 1,
 56     '#description' => t('Your virtual face or picture. Pictures larger than @dimensions pixels will be scaled down.', array('@dimensions' => varia    ble_get('user_picture_dimensions', '85x85'))) . ' ' . filter_xss_admin(variable_get('user_picture_guidelines', '')),
 57   );
barnettech’s picture

hmm seems this code I listed above stops the form from being submitted, just keeps saying user picture required. I will dig a bit to see whats wrong.

deggertsen’s picture

Confirming this. There is currently no option in the Drupal 7 version to make the picture field required on registration.

infines’s picture

Status: Active » Needs work
Road Kill’s picture

Hi Barnettech did you ever find a solution for this.

barnettech’s picture

Sorry I didn't.

Road Kill’s picture

Okay thaanks going to see if I can put something together will post here if I get it working.

barnabas.kecskes’s picture

Component: Miscellaneous » Code
Assigned: Unassigned » barnabas.kecskes
Priority: Normal » Major
StatusFileSize
new1.55 KB

Here is how the .module file should look like after the required changes. I have added the extra option, and also the required modifications in order to get it working. Furthermore, I've changed the weights for the options to make more sense...

NOTE: I was not able to commit a patch – lack of experience. Please feel free to convert use the code to upgrade the module as you will.

<?php
/**
 * @file
 * Reg with pic module file.
 */

/**
 * Implements hook_form_alter().
 */
function reg_with_pic_form_user_admin_settings_alter(&$form, &$form_state, $form_id) {
  $form['personalization']['pictures']['reg_with_pic_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable pictures on registration.'),
    '#default_value' => variable_get('reg_with_pic_enabled', 0),
    '#weight' => -20
  );
  $form['personalization']['pictures']['reg_with_pic_required'] = array(
    '#type' => 'checkbox',
    '#title' => t('Require pictures on registration.'),
	'#description' => t('For this option to have effect, you need to enable user pictures on registration.'),
    '#default_value' => variable_get('reg_with_pic_required', 0),
    '#weight' => -15
  );
  $form['personalization']['pictures']['reg_with_pic_weight'] = array(
    '#type' => 'textfield',
    '#title' => t('Registraton Picture Field Weight'),
    '#description' => t('Set to an integer, positive or negative, to control the weight of the picture field on the registration form.'),
    '#size' => 5,
    '#default_value' => variable_get('reg_with_pic_weight', 0),
    '#weight' => -10
  );
  $form['#submit'][] = 'reg_with_pic_settings_submit';
  return $form;
}

/**
 * Submit handler for user admin settings form.
 */
function reg_with_pic_settings_submit(&$form, &$form_state) {
  // Save enabled variable.
  variable_set('reg_with_pic_enabled', $form_state['values']['reg_with_pic_enabled']);
  // Save required variable.
  variable_set('reg_with_pic_required', $form_state['values']['reg_with_pic_required']);
  // Save weight variable.
  variable_get('reg_with_pic_weight', $form_state['values']['reg_with_pic_weight']);
}

/**
 * Implements hook_form_user_register_alter().
 */
function reg_with_pic_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  // Set picture fieldset.
  $form['picture'] = array(
    '#type' => 'fieldset',
    '#title' => t('Picture'),
    '#weight' => variable_get('reg_with_pic_weight', 0),
    '#access' => (variable_get('user_pictures', 0) && variable_get('reg_with_pic_enabled', 0))
  );
  // Set picture file field.
  $form['picture']['picture_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload picture'),
	'#required' => variable_get('reg_with_pic_required', 0),
    '#size' => 48,
    '#description' => t('Your virtual face or picture. Pictures larger than @dimensions pixels will be scaled down.', array('@dimensions' => variable_get('user_picture_dimensions', '85x85'))) . ' ' . filter_xss_admin(variable_get('user_picture_guidelines', '')),
  );
  // Validate with user module validation function.
  $form['#validate'][] = 'user_validate_picture';

  return $form;
}

/**
 * Implements hook_entity_presave().
 */
function reg_with_pic_entity_presave($account, $type) {
  // Only handle new users that have an uploaded picture.
  // user_save() will handle old users.
  if ($type != 'user' || !$account->is_new || empty($account->picture) || !is_object($account->picture)) {
    return;
  }
  $picture = $account->picture;
  $info = image_get_info($picture->uri);
  $picture_directory =  file_default_scheme() . '://' . variable_get('user_picture_path', 'pictures');

  // Set the new uid since it is typically not set at this point. user_save()
  // will use this uid if set so no problems setting it early here.
  if (empty($account->uid)) {
    $account->uid = db_next_id(db_query('SELECT MAX(uid) FROM {users}')->fetchField());
  }

  // Prepare the pictures directory.
  file_prepare_directory($picture_directory, FILE_CREATE_DIRECTORY);
  $destination = file_stream_wrapper_uri_normalize($picture_directory . '/picture-' . $account->uid . '-' . REQUEST_TIME . '.' . $info['extension']);

  // Move the temporary file into the final location.
  if ($picture = file_move($picture, $destination, FILE_EXISTS_RENAME)) {
    $picture->status = FILE_STATUS_PERMANENT;
    $account->picture = file_save($picture);
    file_usage_add($picture, 'user', 'user', $account->uid);
  }
  // Update user record with picture fid.
  if (isset($account->picture->fid)) {
    $account->picture = $account->picture->fid;
  }
}
BParticle’s picture

This works, great!! I have been following this issue for a long time hoping someone would tackle it. Thanks, barnabas.kecskes

I confirm #16 and #8. While checking out the form, I didn't actually submit it, so I missed this behavior.

Road Kill’s picture

Unfortunately barnabas.kecskes your solution still presents the same problem as before in #8.

fineartist99’s picture

So is there no module or setting to make a user picture required in Drupal 7?

deggertsen’s picture

@fineartist99 Not that I know of at this point. What we ended up using is the pcp module to simply encourage people to upload their picture. It works for us, but obviously doesn't fix making it an option of that it required.

vm’s picture

It seems to me that one could bypass the core user picture functionality and add a core imagefield to the user entity and mark the field as required which would it to the registration page? Of course this would also mean one would have to manually print the field in the .tpl.php file or utilize the displaysuite module to handle display

profile2.module may also come in handy

fineartist99’s picture

I was reading about editing the core here https://drupal.org/node/190815 still do not understand how I can make this happen. If I were to use the profile2.module that would work, but the image field that I added doesn't take the profile pictures place. I established an image field for end users profiles and it worked as it should, only thing though is that the image doesn't take the profile pictures place. The profile picture for the person wasn't set to the image that they uploaded on the registration page via my new field.

Seems like this should be such an easy thing to control but no, seems as if it's impossible!!!!

vm’s picture

only thing though is that the image doesn't take the profile pictures place. The profile picture for the person wasn't set to the image that they uploaded on the registration page via my new field.

that's not going to happen without intervention on your part. Either by manually printing the field or utilizing display suite.

fineartist99’s picture

What would I be manually printing the field or utilizing display suite within?

kleinmp’s picture

Status: Needs work » Needs review
StatusFileSize
new3.57 KB

Here's a patch that should properly require the picture.

caw67’s picture

Issue summary: View changes

patch #23 works!

Northern_Girl’s picture

Hi,

curious to know if the patch (#23) will be commited to a new release?

NG

ifrik’s picture

Patch #23 works.

As long as this patch is not committed, then in would be good to change at least the module description and not state that the module can set the user picture to be required.

thumpers’s picture

I tried Patch #23 with Drupal 7.41 and it did not work...

Donit’s picture

Would it not be better to set up a role-based permission on "picture required"?

anton-staroverov’s picture

A better solution would be an additional validator instead of completely overriding `user_validate_picture` in patch #23:

...
  $form['#validate'][] = 'user_validate_picture';
  $form['#validate'][] = 'reg_with_pic_user_validate_picture';
...
function reg_with_pic_user_validate_picture(&$form, &$form_state) {
  if (empty($form_state['values']['picture_upload'])) {
    form_set_error('picture_upload', t("Picture field is required."));
  }
}