4

How difficult would it be to show a column in the user list (admin/people) that shows the user's ID number? Is this possible?

3 Answers 3

8

It's pretty easy if you're able to install the Administration Views module.

It replaces the default admin/people page with a view, which you can easily customise to add the user id as another column in the table.

If you're not able to use that module there are ways to do it in code, but it's a bit fiddly. I did roughly the same thing a couple of months ago (before I'd come across Admin Views) so let me know if you want me to dig the code out and post it here.

2
  • Excellent suggestion Clive, this looks very promising. Thanks for taking the time.
    – Jolva
    Jul 19, 2012 at 17:42
  • @Jolva: If this answer worked for you, you can accept it to give an extra thank-you to the answerer -- they get some extra rep points and it helps others find the 'best' answer.
    – Hugo
    Oct 7, 2014 at 14:01
5

Implement hook_form_BASE_FORM_ID_alter() in a custom module to add the uid column to the list of people:

/**
 * Implementation of hook_form_BASE_FORM_ID_alter().
 */
function MODULE_form_user_admin_account_alter(&$form, &$form_state, $form_id) {
  $uid_column = array('uid' => array(
    'data'  => 'ID',
    'field' => 'u.uid'
  ));
  $form['accounts']['#header'] = $uid_column + $form['accounts']['#header'];

  foreach ($form['accounts']['#options'] as $key => $row) {
    $form['accounts']['#options'][$key]['uid'] = $key;
  }
}
3
  • Awesome - this method should work with fields added via Profile2 right? Thanks scronide!
    – Jolva
    Jul 19, 2012 at 17:43
  • It could, but it would take a lot more work because that form only knows values in the user table by default. If you needed to pull in Profile2 fields, I'd suggest going the Views route.
    – scronide
    Jul 20, 2012 at 16:33
  • Very useful for the ID. Note that it can't easily be extended to include the email address as it's not included in the query.
    – Deanna
    Sep 13, 2014 at 17:12
0

To fetch the profile2 fields you can just tweak the code like this:

/**
 * Implementation of hook_form_BASE_FORM_ID_alter().
 */
function MODULE_form_user_admin_account_alter(&$form, &$form_state, $form_id) {
  $uid_column = array('uid' => array(
    'data'  => 'ID',
    'field' => 'u.uid'
  ));
  $form['accounts']['#header'] = $uid_column + $form['accounts']['#header'];

  foreach ($form['accounts']['#options'] as $key => $row) {
    $userProfile = user_load($key);  // this will have all user profile object which can be used below instead of $key.

    $form['accounts']['#options'][$key]['uid'] = $key;  // replace $key with the object value you need.
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.