The field for uploading a user's picture provided by Drupal core is not a real field, so this module automatically puts it on "Edit account", rather than "Edit profile".

However, it seems like on many sites it would be more appropriate to consider that part of the user's profile, so maybe we should at least have an option for it to appear there.

Comments

milos.kroulik’s picture

+1

BenK’s picture

Subscribing

rolandk’s picture

+1

damj’s picture

+1 and the signature field too

Tsubo’s picture

+1 any movement on this likely?

Tsubo’s picture

I've taken a stab at this. I'm not familiar with the process of patching so I'll just include the code here. Two functions in the existing module need modification: Replace the two existing functions with these two and you should be good to go. I've included comments....

/**
 * Implements hook_form_FORM_ID_alter().
 */
function edit_profile_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  // Hide all user fields when displaying the main "Edit account" form. (We
  // need to explicitly check that we aren't on the "Edit profile" form or on a
  // different category under "Edit account", since this alter hook gets called
  // in those contexts also.)
  if ($form_id != 'edit_profile_user_profile_form' && $form['#user_category'] == 'account') {
    foreach (array_keys(field_info_instances('user', 'user')) as $field_name) {
      $form[$field_name]['#access'] = FALSE;
    }
  }
  // Hide the User Picture form field so we can display on the 'Edit profile' form only
  if(isset($form['picture'])){
    $form['picture']['#access'] = FALSE;
  }
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function edit_profile_form_edit_profile_user_profile_form_alter(&$form, &$form_state) {
  // Hide all form elements when displaying the "Edit profile" form, except
  // user fields and other elements needed for the form to function.
  $field_names = array_keys(field_info_instances('user', 'user'));
  $form_fields_to_keep = array_merge($field_names, array('actions', 'form_build_id', 'form_token', 'form_id'));
  foreach (element_children($form) as $key) {
    if (!in_array($key, $form_fields_to_keep)) {
      $form[$key]['#access'] = FALSE;
    }
  }
  // Re-instate the User Picture form element after all other default account form fields have been removed
  if(isset($form['picture'])){
    $form['picture']['#access'] = TRUE;
  }
  // Only show the 'submit' button on this form, and hide any others (such as
  // 'cancel account').
  foreach (element_children($form['actions']) as $key) {
    if ($key != 'submit') {
      $form['actions'][$key]['#access'] = FALSE;
    }
  }
}

I also deleted the function 'edit_profile_field_extra_fields_alter(&$info)' so I could continue to control the position of the Picture field in relation to other fieldable entities via Manage Fields - which this module otherwise prevents.

If anyone has a more elegant solution - please let me know.

David_Rothstein’s picture

Thanks for starting on this. Note that http://drupal.org/patch may be helpful in learning how to turn this into a patch.

I took a quick look and had a couple comments:

  1.   // Re-instate the User Picture form element after all other default account form fields have been removed
      if(isset($form['picture'])){
        $form['picture']['#access'] = TRUE;
      }
    

    It's probably not safe to unilaterally set it to TRUE (since access may have been denied for other reasons). I think it would be better to add it to the list of elements that we don't set to FALSE in the first place.

  2. I also deleted the function 'edit_profile_field_extra_fields_alter(&$info)' so I could continue to control the position of the Picture field in relation to other fieldable entities via Manage Fields - which this module otherwise prevents.

    I would think we still need to hide the other "extra fields" that edit_profile_field_extra_fields_alter() is hiding, and only let Picture be on the list of extra fields? Since that's the only one that will appear on the Edit Profile screen with the other user fields.

    Actually, there might not be any code change necessary at all here yet... If I'm not mistaken, until #967566: Several important Core User settings need to implement hook_field_extra_fields() is fixed the Picture field doesn't show up on the Manage Fields tab anyway?

microwavemayo’s picture

For those needing a quick fix, you can alter this right in your template.php file or a custom module with the following:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOURTHEME_form_edit_profile_user_profile_form_alter(&$form, &$form_state) {
  $form['picture']['#access'] = TRUE;
}


/**
 * Implements hook_form_FORM_ID_alter().
 */
function YOURTHEME_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
	$form['picture']['#access'] = FALSE;
}
Tsubo’s picture

Category: feature » support

Can I just check the status on this. I'm currently still running core7.8 - but can I assume if I upgrade to 7.10+ that this is solved?

duaelfr’s picture

Version: 7.x-1.0-beta1 » 7.x-1.0-beta2
Status: Active » Needs review
StatusFileSize
new3.32 KB

Here is a patch introducing a new settings page where the administrator can choose to move the user picture to the profile edit page or not.
I respected #7 advice by not overriding #access attribute.

I hope you will find this useful.

This patch is part of the #1day1patch initiative.

David_Rothstein’s picture

Category: support » feature

Didn't try it out, but looks great overall. Thanks!

Just a couple small comments:

+    'access arguments' => array('configure profile edit page'),

Don't know if it's really necessary to add a new permission to the module just for this settings page - maybe just use 'administer users' for starters?

+function edit_profile_settings_form() {
+  $form = array();

The function should take $form and $form_state as parameters (since those are passed in and $form could in theory be non-empty), rather than defining $form as an empty array.

portulaca’s picture

+1

NineAllexis’s picture

I end up disabled the default user pictures feature and creating my own field in Config/People.
That's perhaps because I need to segregate user uploads to each of their own folder. Which is kinda impossible configuration with the default user pictures settings.

duaelfr’s picture

@NineAllexis :
It is another way to go but a lot of modules rely on the user picture and not on a custom field so you may experience some issues.

@David_Rothstein :
I finally rerolled the patch with the change for the form function but I left the new permission. Indeed, there are a lot of discussions about splitting the "administer users" permission because it currently give too much rights to the user. As this won't be fixed in core before D8 I think it is a bad idea to make this choice.

I prefered to make a new patch instead of committing this fix on my own to get your final opinion about this permission.