I have a entity reference field with entity mode set to views:filter by an entity reference view.
My view has a set of users limited to certain roles with search field set to their real names. (admin and moderators are excluded from the view and i expose users to search only on their real name hiding usernames and uid's)

The set up worked fine with realname 7-1.1. Update to the latest release breaks the setting and always defaults to the realname auto complete exposing all users without respecting the view used by entity reference. (along with starts with and contains)

Also the users username is always exposed which could be a risky for sites exposing the auto complete for user added content.(admin and moderators are exposed in mine)

Realname should stick to what it does best and avoid changing the behavior of entity reference in my opinion.

Is there something i can do to get my view to work with the latest real name?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nevergone’s picture

nevergone’s picture

FileSize
953 bytes

Previous patch is broken autocomplete.

hass’s picture

The enityreference patch was very long in issue queue and fixed several issues for my users. You have not helped reviewing it and It was as not a bad commit. It made entityreference useable with realname.

hass’s picture

japerry’s picture

I think part of the issue here is that we're not altering the query in buildEntityFieldQuery for the EntityReference autocomplete class handler.

If we implement a hook_query_alter on this tag, that might fix the query side of this issue. Similar problem in commons reported here: #1965862: Entityreference autocomplete for users still searches by username but displays full name instead

hass’s picture

SantVim’s picture

Title: Real name changes the entity reference behavior » Real name changes the entity reference behavior with views

@hass this is totally different from that issue. The issue here is that realname 1.2 is taking over the finely tuned autocomplete list of users from views and entity reference when used with views already has the functionality to search users with whatever fields necessary.

Steps to reproduce this

1. with realname 1.2, entity reference and views installed add a new view with show users, un check page and block and click continue and edit
2. Now we have a master list of users click add new display and select entity reference.
3. Now the format should be Entity Reference list and show inline fields with user:name as field.
4. Remove the user:name from fields and add Realname: Real name
5. Goto settings next to format and click on Realname: Real name as search field and save.

Now lets create a entity reference field in the content type

1. create an entity reference field with target type:user and ENTITY SELECTION mode to views:filter by an entity reference view and select the view we created before.

With this setup if you input data in the autocomplete field

In realname 7.x-1.1 - the display will only show the fields from the view with the search term limited to the one we choose in views (above we have Realname: Real name ) so we get only the real name. I can filter the results in the view to show users of only a particular role and all things done by views.

In realname 7.x-1.2 - the display wont take the view into consideration and always displays the realname with the username.

Hope this sheds some light on the issue which is definitely not a duplicate. Hope i was convincing :)

#updated the title added (with views)

titouille’s picture

Patch from #2 seems to partially resolve the problem, but what append if it's not a "view" plugin but a "my_custom" plugin ??

I don't know if it's a good solution, but I made a little patch to add plugin checkboxes on realname administration to disable realname autocomplete application on specific handler plugins.

julou’s picture

I have the same issue as Dhamub.
In my opinion, real name should not override the #autocomplete_path when the entityreference field is set with a view (all the more so as the real name can be displayed using the view fields).

I suggest to replace realname.module line 409:
if ($context['field']['settings']['target_type'] == 'user') {
to
if ($context['field']['settings']['target_type'] == 'user' && $context['field']['settings']['handler'] != 'views') {

Could you please commit this change to dev if you think it is appropriate? Thank you in advance.

julou’s picture

Status: Needs work » Needs review

Up

#9 has been working fine for me so far. Is there any drawback to implementing it in the dev version?

hass’s picture

Status: Needs review » Needs work

There is no patch to review.

julou’s picture

Status: Needs work » Needs review
FileSize
761 bytes

Well, that was a one liner… but here is a patch!
Thank you in advance for reviewing.

rudiedirkx’s picture

Status: Needs review » Needs work

Checking for != 'views' isn't smart. Realname should only interfere if it's a known plugin that uses the known autocomplete. Only 'base' does that, so it should check for == 'basic'.

rudiedirkx’s picture

Actually, what realname 'should' do is override Drupal's autocomplete menu callback, not override widgets' #autocomplete_path. That way all the autocomplete elements get the realname magic, but only if it replaces the normal boring Drupal autocomplete. If you override a widget, you never know what you're overriding exactly.

hass’s picture

Normally a widget type user should be safe. There may be edge cases, but we can workaround for these.

rudiedirkx’s picture

If it overrides the menu callback, all widgets using the normal user autocomplete will have been 'upgraded' automatically. Now you'd have to explicitly set the #autocomplete_path to realname's. Maybe not so good for backward compatibility though.

hass’s picture

The only known issue seems to be a problem where Realname fights with OG. One of them must win.

I think the root cause is a missing field API function in entity reference and that I had no other option.

julou’s picture

The only known issue seems to be a problem where Realname fights with OG. One of them must win.

No, in my case, I'm not using OG and still have the problem that realname auto complete always expose all users without respecting the view used by entity reference.

Unfortunately I'm not familiar enough with autocmoplete to be able to really follow your discussion.

hass’s picture

@julou: Can you share a detailed repro case, please.

rudiedirkx’s picture

Yeah, it has nothing to do with OG. The use case is very simple:

  1. Create an entity reference with handler type Views instead of Basic, and filter the View on a role.
  2. The autocomplete is overridden with Realname's, the View isn't used, the role filter isn't used, very wrong results.

#12 fixes it (altough I used #13 because it's correcter), but then you have no Realname magic =( (but at least you have the correct View with the correct role filter)

SantVim’s picture

@rudiedirkx in the view you can still use Real name as the search field.

rudiedirkx’s picture

@Dhamub Aaaaaaaw yeah! I didn't know Entity Reference had that! That is truly perfectly awesome! Thanks mang!

hass’s picture

What does this mean?

rudiedirkx’s picture

It means nothing to the issue. If you apply patch #12, it can work a way I didn't know. But you need the patch.

I said Needs Work in #13, because I think that's more correct, but if nobody agrees, patch in #12 is RTBC.

muhleder’s picture

Status: Needs work » Reviewed & tested by the community

Just run into this as well. The patch in #12 is correct, if the autocomplete is coming from an entityreference view then the override is not needed as realname can be applied manually in the UI as outlined in #21.

Specifically the code in realname_field_widget_form_alter() breaks entityreference views in that it replaces the view with an unfiltered list of all users. To be honest you could just remove the realname_field_widget_form_alter() function entirely and state that people need to use a view if they want realname integration for entiryreference autocomplete fields.

hass’s picture

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

@hass: Did you say this issue "Needs work" because of comment #25? I have come across this issue myself and need to have this fixed at some point and would love to help however I can.

What are your thoughts?

mgbellaire’s picture

@NancyDru, do you have any ideas on what the proper fix for this problem could be? The patch #12 has worked for the development team I work for, but it sounds like it isn't the _proper_ way of fixing this issue. What would you suggest?

rudiedirkx’s picture

IMHO realname_field_widget_form_alter() should be removed entirely, because the widget is none of Realname's business. If it really has to, it has to be sure it only overrides the standard autocomplete. Checking for != 'views' is not enough, because there are more ER widgets out there. They must NOT be overridden, so only == 'base' should be overridden.

Patch attached.

Again, last time, Realname shouldn't do this at all IMO.

rudiedirkx’s picture

Status: Needs work » Needs review
hass’s picture

Could you add tests, please? We schould make sure this does not break in future.

hass’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests
Abelito’s picture

The patch in #29 worked for me to solve this issue with the EntityReference module autocomplete: https://www.drupal.org/node/1978274

hass’s picture

Version: 7.x-1.2 » 7.x-1.x-dev
sumthief’s picture

Patch from #29 works good on my current project for realname of version "7.x-1.3".

Also this patch looks good (I think @rudiedirkx absolutely correct - we should override only 'base' field behavior).

sumthief’s picture

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

Status: Reviewed & tested by the community » Needs work

Needs tests

jaxtheking’s picture

I stumbled upon this from the entityreference issue queue, totally unaware Realname may be causing such issue.
Glad to report the patch in #29 worked great for me.
Thanks @rudiedirkx

nimek’s picture

patch from #29 works great - this should be default expected real name behaviour +1 for commit

rudiedirkx’s picture

@hass Could you point me in the right direction, test-wise? How do I test a widget? Build and render an entity form?

hass’s picture

Not sure how, but we should make sure everything is shown and maybe does not throw errors.

omidehghanZD’s picture

patch from #29 works great for me on version 7.1.3 .

akolahi’s picture

Patch #29 resolved the issue with Entity Reference fields for me as well.

joelstein’s picture

Status: Needs work » Reviewed & tested by the community

I encountered this same issue, and after looking in the code (before finding this issue) I came to the same conclusion, that Real Name should not alter the Entity Reference autocomplete widget when using Views to select the entities, since we can format the results however we want in Views. Patch is simple, focused, and does exactly that.

hass’s picture

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

Manually applied to v1.3 and it worked for me!

Thanks for all the hard work on this one!

nimek’s picture

@hass

Man patch is 2 years old and everybody confirms that it is working without complaints so what is the real reason to not set status as RTBC???

nevergone’s picture

FileSize
30.36 KB

@nimek: