Now that Realmame support has been committed to the Private Message module, we should think about adding it to Userpoints--specifically for the administrative "Add" points form (admin/config/people/userpoints/add). Currently, the autocomplete on that form only shows actual usernames... but it would be nice if the autocomplete could show realnames as well (using perhaps identical settings to what Private Message uses).

This would help solve the current issue that when you have the Realnames module enabled, the site admin awards points to usernames but their realnames show up in the points transactions list. As a result, it can get a little confusing.

--Ben

Comments

berdir’s picture

Title: Add Realname support for "Add" points form » Provide a backwards-compatible realname autocomplete
Project: User Points » Real Name
Component: Code: userpoints API » Code

I think it's realname.module's job to provide a username autocomplete callback. To keep it backwards compatible, it could search for both usernames and realnames, display the realname (maybe both?) in the autocomplete suggestions and then use the username as the key.

I am not sure if it should actually override the default autocomplete, maybe it would be better to provide a separate one, although that would require that all modules which want to do this add a special check and use the other one. Maybe configurable even?

berdir’s picture

Oh, and I can of course provide a patch based on whatever we decide here :)

moonray’s picture

StatusFileSize
new4.96 KB

Perhaps you can use code from this module I wrote as a base. It's a bit customized and would need to be partially re-written to work for realname module.

jzornig’s picture

Add the following to realname.module to override the user autocomplete with realname autocomplete.

/**
 * Implement hook_menu_alter to replace user autocomplete with realname autocomplete
 */
function realname_menu_alter(&$items) {
	// Implement realname autocomplete.
	$items['user/autocomplete']['page callback'] = 'realname_autocomplete';
}
jzornig’s picture

Status: Active » Needs review
brightbold’s picture

Confirming that this patch worked for me. Yay! Greatly appreciated.

xDudditzx’s picture

This doesnt work for me in Drupal 7.15 with -dev
EDIT: Sorry, I did not have pm module option enabled.
Works fine

WorldFallz’s picture

Status: Needs review » Active

there's no actual patch to review here

jzornig’s picture

Status: Active » Needs review
StatusFileSize
new476 bytes

Patch for review included.

hass’s picture

Yes, if users only see their realname in autocomplete field we need to search for both or only the realname as this is what the users expect. We just has this failure here and it is very confusing to the users.

Above patch is all we need?

hass’s picture

Fixed code style (tabs) and new D7 Implements.

hass’s picture

Status: Needs review » Reviewed & tested by the community

This works as expected. I expected this works for entityreferences too, but it does not :-(. entityreferences follow up patch is in #1722112: Autocomplete for entityreference fields

hass’s picture

Users are completly confused and we cannot explain them that the autocomplete requires to enter the username, but it shows the real name as found match/suggestion. Therefore they are not able to find other people as usernames could also be very strange and random names, too.

This is a clear usability fail.

Taxoman’s picture

Title: Provide a backwards-compatible realname autocomplete » Replace user autocomplete with realname autocomplete
Category: feature » bug
Status: Reviewed & tested by the community » Needs work
hass’s picture

Status: Needs work » Reviewed & tested by the community
hass’s picture

Status: Reviewed & tested by the community » Needs work

There seems to be a validation issue in node forms. This fails and the form error is shown:

  // Validate the "authored by" field.
  if (!empty($node->name) && !($account = user_load_by_name($node->name))) {
    // The use of empty() is mandatory in the context of usernames
    // as the empty string denotes the anonymous user. In case we
    // are dealing with an anonymous user we set the user ID to 0.
    form_set_error('name', t('The username %name does not exist.', array('%name' => $node->name)));
  }
hass’s picture

Oh, no it's my patch in #1722112: Autocomplete for entityreference fields that causes this issue.

nibo’s picture

The patch is not really complete. I can search after a real name and get those as suggestion, but the username still gets shown in the textfield after selecting the suggested real name.

berdir’s picture

Status: Needs work » Reviewed & tested by the community

That is by design. Actually handling realnames as the values requires changes in the modules that provide the autocomplete field and a lot of complex logic to deal with duplicates and so on.

Can't be changed here.

hass’s picture

Can we get this committed now? It looks like the maintainers are not really active.

May I get co-maintainer permissions, please?

jonanthony’s picture

#subscribe - really useful patch

dave reid’s picture

Status: Reviewed & tested by the community » Fixed

I tweaked this a bit to move the realname_menu_alter() to below realname_menu() like it should be, and in the autocomplete added a ' ($acccount->name)' to the results if the format_username() result does not match $account->name. This should maybe help some of the WTF with finding a specific username in the results and clicking it, the value in the text field not matching what the user clicked.

Committed and fixed in 7.x-1.x. http://drupalcode.org/project/realname.git/commit/32413b1

eminencehealthcare’s picture

This is great Dave. I am wondering if there is a way to display the realname in the actual field though (instead of in the dropdown to select the field) Is this possible? String override or something?

dave reid’s picture

This is not really possible right now. Node forms that use the autocomplete expect to have the actual login name in the field since it is used for validation. Displaying real name would cause all those forms to fail validation.

eminencehealthcare’s picture

Thanks for the quick response. That makes sense. I think I will just "fake it" by using a rule to set node author from user reference field and then fill another field with author realname.

askibinski’s picture

Just posting here a reference to #1935218: Hide blocked users in autocomplete where I attached a patch to hide blocked users from this autocomplete.

Renee S’s picture

An alternate solution, @eminencehealthcare, to the display thing could be to use a custom formatter, using a View that takes the username and returns a realname.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

molenick’s picture

Issue summary: View changes

Reopening this, it seems to never have been resolved. To me it seems confusing and counterintuitive to people on a live site.

In my current use case I'm using realname and entityqueue to populate some user queues. The autocomplete field doesn't work as expected - it expects input from the drupal user account but returns output from the Real Name field.

To me it seems like the most straightforward solution is to disable realname for autocomplete, but I understand this may be contentious.

julou’s picture

Status: Closed (fixed) » Active

I have the same problem as #29: autocomplete works on user account, it proposes real names in a drop down list and finally shows the user account.

Issue changed to active.

hass’s picture

Status: Active » Closed (fixed)

That is the way how core works. We cannot change this.

johannez’s picture

Hello guys,

I ran into similar issues as described above. I use the Entityqueue module for staff listing views. The autocomplete field was displaying the first name and last name nicely, but didn't accept any spaces, nor did it accept the username. I took a look at your override there for the autocomplete path and noticed that the EntityReference field must have changed their widget structure a bit in the last year.
After I adjusted the widget in the hook_widget_form_alter your /realname/autocomplete kicks in with all it's beauty and let's me drill down to my user with spaces and usernames.

I attached my simple patch and hope you can get it in for the next dev version.

Cheers,
Johannes

johannez’s picture

Sorry, forgot to include the widget type name change. In the past it was entity_reference, but that changed to entityqueue_dragtable. Please use this instead of #32.

Abelito’s picture

The patch in #33 worked for me to solve this issue with the EntityReference module autocomplete: https://www.drupal.org/node/1978274
..but this one looks more directly relevant, and it worked too: https://www.drupal.org/node/2261665#comment-10513164

heddn’s picture

Status: Closed (fixed) » Needs review

Let's get some eyes on the patch.

The last submitted patch, 32: realname-985944-fix-autocomplete-path-32.patch, failed testing.

The last submitted patch, 32: realname-985944-fix-autocomplete-path-32.patch, failed testing.

The last submitted patch, 32: realname-985944-fix-autocomplete-path-32.patch, failed testing.

The last submitted patch, 32: realname-985944-fix-autocomplete-path-32.patch, failed testing.

johannez’s picture

hass’s picture

Status: Needs review » Needs work

Code wise this can only wrong