I have to say that I am loving the real name module right now, but there is an important issue that I cannot figure out. Real name is working right now in views and the profiles of the users but for some reason it does not seem to be working with user references. I have a content type that display user references as a field, but it displays their username like (tomjones45) rather than (Tom Jones). I was wondering if anyone has encountered this issue or is facing a similar problem?

Files: 
CommentFileSizeAuthor
#47 entity-label-1194086-46-widgets.patch7.67 KByched
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]
#45 entity-label-1194086-45-formatteronly.patch11.29 KByched
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity-label-1194086-45-formatteronly.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]
#43 entity-label-1194086-43.patch18.56 KByched
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]
#39 user-reference-autocomplete_on_realname.patch1.11 KBliquidcms
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in user-reference-autocomplete_on_realname_0.patch.
[ View ]
#26 1194086-user-reference-use-entity-label.patch9.08 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]
#21 1194086-user-reference-use-entity-label.patch9.08 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]
#19 1194086-user-reference-use-entity-label.patch9.14 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1194086-user-reference-use-entity-label_2.patch.
[ View ]
#18 1194086-user-reference-use-entity-label.patch7.66 KBDave Reid
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1194086-user-reference-use-entity-label_1.patch.
[ View ]
#12 1194086-user-reference-use-entity-label.patch1.27 KBmariagwyn
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]
#4 1194086-user-reference-use-entity-label.patch1.27 KBDave Reid
PASSED: [[SimpleTest]]: [MySQL] 12 pass(es).
[ View ]

Comments

It likely means that the code is not using format_username() to display the names of the accounts. Are you using the References module for your user references?

Yes, I am using the references module. Is there a way to get user references to use the format_username() function?

Subscribing. I have the same problem with Real Name when using References module.

Project:Real Name» References
Version:7.x-1.0-rc1» 7.x-2.x-dev
Component:Code» Code: user_reference
Status:Active» Needs review
StatusFileSize
new1.27 KB
PASSED: [[SimpleTest]]: [MySQL] 12 pass(es).
[ View ]

The problem is user_references doesn't use the proper entity_label() function (which calls format_username()) to display a user's name. Best practice when displaying the title of an entity is to always use entity_label().

That was fast! Unfortunately, the patch breaks my site when a user reference field is displayed...

Subscribing. The above patch Is it working or not? I manage to get the same result by changing
$query = db_select('user', 'u')
to
$query = db_select('realname', 'u')

in user_reference.module, line 304, but I don't believe it's a proper solution.

sub

Status:Needs review» Needs work

I ran into this problem too. I tried the patch in #4 and it broke the site with the WSOD PHP Fatal error:  Call to undefined function user_load_mulitple() I also tried the hack in #6 and it failed as well. Based on #6 I changed the same function to have the following and this worked for me:

<?php
 
if ($uids_query) {
   
$query = db_select('realname', 'u')
      ->
fields('u', array('uid', 'realname'))
      ->
condition('u.uid', $uids);
   
$titles += $query->execute()->fetchAllKeyed();
  }
?>

And now I found the problem in the patch from #4. It works fine, but the function "user_load_multiple" was spelled wrong.

jason: can you correct and upload the patch? I can test...

Maria

I don't have a good way of creating or using patches right now. I do everything by hand. But you can use the patch from #4 and on line #19 of the patch have it say
+    $accounts = user_load_multiple($new_uids);
instead of
+    $accounts = user_load_mulitple($new_uids);
The change to the patch can be done before its applied.

StatusFileSize
new1.27 KB
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]

I just applied the patch in #4, with spelling correction from jason89s. Seems to work. I am attaching the patch, but if I do it wrong, be nice b/c I have never attached a patch before.

Status:Needs work» Needs review

That's what I get for not testing my own patch. :)

Status:Needs review» Needs work

Hm. I applied this patch on my live site. While it does indeed show the real name in user reference fields, when I save content with this field present, I get this error:

Error message
Presenter(s): name mismatch. Please check your selection.

This is on a name that worked just fine before I edited the content.

In my logs I noticed the following, which match the time I applied the patch: "Guest" generates the following errors:

Warning: array_intersect_key() [function.array-intersect-key]: Argument #2 is not an array in _user_reference_get_user_names() (line 310 of /home/site/public_html/sites/all/modules/references/user_reference/user_reference.module).
Warning: array_diff_key() [function.array-diff-key]: Argument #1 is not an array in _user_reference_get_user_names() (line 301 of /home/site/public_html/sites/all/modules/references/user_reference/user_reference.module).
Warning: array_combine() [function.array-combine]: Both parameters should have at least 1 element in _user_reference_get_user_names() (line 298 of /home/site/public_html/sites/all/modules/references/user_reference/user_reference.module).

These errors are generated when a node that has no user reference field is visited.

reversed patch, errors disappeared, and some of my pretty real names are gone. I will patch again when something is up.

I'm experiencing those same errors as well, reversing the patch fixed the errors.

Dave, any suggestions on the patch? I am happy to test another version.

Status:Needs work» Needs review
StatusFileSize
new7.66 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1194086-user-reference-use-entity-label_1.patch.
[ View ]

Ok, comprehensive patch to get both user and node references to use entity_label(), entity_uri() and use the proper object load functions. I'm guessing all the odd loading is because user_load() was not cached in Drupal 6, but now since we have the entitytype_load_multiple functions - the results are stored in a static cache.

I tested both the node and user ref fields with all three types of widgets (autocomplete, select, checkboxes) to ensure that there are no XSS security regressions from this patch.

StatusFileSize
new9.14 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1194086-user-reference-use-entity-label_2.patch.
[ View ]

Fixed a couple of stray cleanups.

Status:Needs review» Needs work

The last submitted patch, 1194086-user-reference-use-entity-label.patch, failed testing.

StatusFileSize
new9.08 KB
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]

Resolved conflict.

Status:Needs work» Needs review

Just applied it to most recent dev. It looks good so far! I will report back if I discover errors. Thank you! I have a whole bunch of professors who are very uptight about how their names appear.

Subscribing.

Status:Needs review» Needs work

#21 is working fine for me for the default formatter, but not with plain text. With plain text, I get nothing rendered at all. :-(

Status:Needs work» Needs review
StatusFileSize
new9.08 KB
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]

Dang, you beat me to finding that.

Status:Needs review» Reviewed & tested by the community

#26 fixed that. Yay Dave!

Working great for me.

i can't apply this patch now. it doesnt work neither with beta 3 nor with last dev.

[u4388@citrine references]$ patch < 1194086-user-reference-use-entity-label_4.pa                                                   tch
can't find file to patch at input line 5
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/node_reference/node_reference.module b/node_reference/node_referen                                                   ce.module
|index 726ad3a..dd0d152 100644
|--- a/node_reference/node_reference.module
|+++ b/node_reference/node_reference.module
--------------------------
File to patch: node_reference/node_reference.module
patching file node_reference/node_reference.module
Hunk #1 FAILED at 239.
Hunk #2 FAILED at 255.
Hunk #3 succeeded at 382 (offset -12 lines).
Hunk #5 succeeded at 561 (offset -11 lines).
Hunk #7 succeeded at 776 (offset -11 lines).
2 out of 7 hunks FAILED -- saving rejects to file node_reference/node_reference.                                                   module.rej
can't find file to patch at input line 115
Perhaps you should have used the -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/user_reference/user_reference.module b/user_reference/user_referen                                                   ce.module
|index e1b226f..584a269 100644
|--- a/user_reference/user_reference.module
|+++ b/user_reference/user_reference.module
--------------------------
File to patch: user_reference/user_reference.module
patching file user_reference/user_reference.module
Hunk #1 succeeded at 252 (offset -2 lines).
Hunk #3 succeeded at 372 (offset -2 lines).
Hunk #5 succeeded at 549 (offset -2 lines).
[u4388@citrine references]$

then i want to reference any user, i type for example: admin, but in autocomplete, hist full name is suggested.

Status:Reviewed & tested by the community» Needs work

This patch adds a node_load() or user_load() to every autocomplete. And it introduces node_load_multiple() and user_load_multiple() to every potential reference. We've always tried to avoid the loads because the potential references list can be huge, and each individual referenced entity can also be huge.

This needs some benchmarking to make sure performance is not impaired when there are a massive number of large referenced entities. I know we have the new ways of caching the nodes and users so maybe it's OK, I'd just like to have someone confirm that this change isn't going to degrade performance.

Status:Needs work» Needs review

Then, needs review is the more apt status.

I also want to note that http://drupal.org/project/entityreference uses a similar technique to what is used here -- a direct query of the table that avoids entity_load(). Entity Reference might become the successor to this project as a more generic module that can 'do it all', so you might want to pose this idea on that project as well.

thanks Dave for pointing me to this from here: #1296254: userreference formatter where i did up a quick module last night to do the formatter part of this.. oops.. oh well.

couple things i noticed using this patch instead of my new module: my approach was to add new formatters: http://screencast.com/t/ljyPBu1ytGjE - your patch works great for what i need; but wouldn't it be possible someone might want the actual username?

also, i looked very quickly at the patch and had high hopes for this fixing the autocomplete (plus Karen's comment in #30 makes me think i am missing a config somewhere?) - but it doesn't seem to fix the autocomplete issue (for userref fields; havent yet tried on harder case of fixing noderef autocompletes).

is this still being worked on or should i continue with the autocomplete fix i was going to do in my module and just do it as a patch for References?

In regard to #32: entityreference doesn't avoid entity_load() at all. We do query the tables directly (because we have no other choice), but we only get a list of ids and call entity_load() on it before using it.

Hi - I have been using this patch for about a month now and it works great. Can we get the patch committed?

as per my comments in #33 i think this still needs work - or at least perhaps just a definition of the spec for this.

i think the autocomplete needs to complete on the realname - is this not seen as a required part of this?

i can fix the patch to do this if we can agree that it is a necessary part of this (and that it isn't there now - i don't think it is; although code looks like it was modified in that area)

any update on at least the intent of this fix. or is this a bug somewhere else?

as i mentioned above, even though the autocomplete field now displays realnames; it doesn't do search on them.. which still makes this relatively useless for many applications (i guess pretty much all of them)

i guess for now i will assume that is a bug and look at fixing this in references module.

It would be great to see a working autocomplete with realname. Any work in progress somewhere?

StatusFileSize
new1.11 KB
FAILED: [[SimpleTest]]: [MySQL] Invalid patch format in user-reference-autocomplete_on_realname_0.patch.
[ View ]

i submitted this patch on References module a while back: http://drupal.org/node/1234656#comment-5161934

but accidentally posted on wrong project.. as the issue started there. so will post here as well

Status:Needs review» Needs work

The last submitted patch, user-reference-autocomplete_on_realname.patch, failed testing.

Interested in regards to the name field module that also has the user name formatting option. This would be impossible to do this via the database as there are 5 columns that could be formatted in an infinite number of combinations once it has applied the given name format.

Regarding the performance impact :
- It's sad that we add that much full entity_loads() just to get the node titles and user names, but that's how D7 works - and that's also partially because D7 has multiple_load and static caching.
- That's pretty much what we forced upon Views as well.
- That's how Entity Reference works already, and we're not trying to be smarter than them...

What worries me more is the fact that autocomplete widgets now display the entity_label() (i.e possibly "Real Name" if realname.module is enabled) in the filled values and in ac suggestions, but still do the matching against the actual node.title or user.name db column. The resulting UI is inconsistent : the values that come pre-populated when editing an existing node or when clicking an ac suggestion are not themselves within the set of matchable strings. No re-entrance.

I don't see any workaround : entity_label() and the associated 'label callbacks' can alter display values all they want at runtime, but doing an autocomplete match still requires querying one given db column somewhere. And ad-hoc patches like #39 are obviously not the solution.

However, "that's how Entity Reference works already, and we're not trying to be smarter than them..." also applies here, and I'm OK committing this to References. This will need a reroll, though, I'll try to take care of that.

Status:Needs work» Needs review
StatusFileSize
new18.56 KB
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]

Here's an updated patch for the current state of 7.x-2.x-dev.

Like @liquidcms, I'm interested in being able to do the autocomplete search on the RealName. Is that achievable given @yched's points in #42 and if so is it reasonably part of this request or should it be a different issue?

Content administrators (on two different sites) don't necessarily know people's usernames, so if the person has picked something obscure the only way to get them to autocomplete is to look up their username in the People list, (which they may not have the proper permissions to view). So being able to autocomplete on RealName is a high priority for them, but I don't know how technically achievable it is.

If not possible as part of References core, maybe @liquidcms's patch could be converted to a custom module for people who need that particular ad-hoc solution? I'm assuming the reason that's not a good global solution is that is it designed only one specific use case, but there may be other reasons. People who understand the core issues here — what's the best way to proceed for those of us who need this functionality?

StatusFileSize
new11.29 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch entity-label-1194086-45-formatteronly.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.
[ View ]

Actually I'm still pondering on the "widget" side.

For now, committed the attached patch - "formatters" only.

Status:Needs review» Needs work

The last submitted patch, entity-label-1194086-45-formatteronly.patch, failed testing.

Status:Needs work» Needs review
StatusFileSize
new7.67 KB
PASSED: [[SimpleTest]]: [MySQL] 14 pass(es).
[ View ]

Which leaves the following part still uncommitted for widgets.

Upgrade references to 7.x-2.x-dev - 2011-Dec-22, and it does work.

@SangersDrupalDude : yup, it now works in userref values displayed by formatters.
The issue is still open for the "widgets" side, which still refer to the core user name - see comments #42 - #45 - #47.

I have been ported to D7
Userreference Realname

Just a note that we've been running this patch on Palantir.net for some time without issue. Admittedly it's not a big site, but it's a data point. This really should get committed eventually...

Crell, can you please let me know which patch is that ? The one in #47 ?