I needed functionality for Entity Reference Autocomplete module so I wrote a patch to support it. The author is writing the tags we need and we just need to alter it.

See https://www.drupal.org/node/2353169#comment-10357499

If anyone has a better way to do this let me know.

Patch Incoming.

Comments

Derimagia created an issue. See original summary.

Derimagia’s picture

Adding patch.

Derimagia’s picture

Status: Active » Needs review
nancydru’s picture

Status: Needs review » Needs work

First, there is no check for the existence of the Entity Reference Autocomplete module, so those who don't use that would encounter a failure with this.

Second, the usual response to stuff like this is "We do not put in module-specific support; modules should largely be agnostic about other modules."

I don't really understand the problem to be solved here. Can they not just do a format_username()?

Derimagia’s picture

1) It's in a hook_query_tag_ALTER so if the tag never gets added this code won't get called. Adding a module_exists wouldn't hurt.
2) This is kind of difficult because even though I understand this the code should exist somewhere, don't you think? If entity reference autocomplete adds it then they will have module specific code in there module. How else would you add this functionality?
3) Entity Reference Autocomplete has an autocomplete that let's you search based off of a name. By default this will only do their username, not their rename. So if the name is "John Doe" but there username is "jd123" and you search for "John" the user won't come up without this patch.

Agreed the patch needs work (The tag changed at the very least) though.

Derimagia’s picture

Status: Needs work » Needs review
StatusFileSize
new1.38 KB

Updating patch to add module_exists (just to be sure) and then updating tag used. Let me know if you need anything else.

nancydru’s picture

Thanks. I would like some other eyes on this.

da_cloud’s picture

Just installed the above patch on one of our sites that uses both the realname module and the entityreference_autocomplete and I can confirm that the above patch works like a charm.

hass’s picture

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

StatusFileSize
new19.23 KB
new21.15 KB

I have not worked your patch.
When I select a widget "Autocomplete" to refer to the user - everything is OK, the search is carried out on the actual user name. However, when choosing under the same conditions widget "Autocomplete style tags", the search is carried out exclusively by login and user id.

Autocomplete:
autocomplete

Autocomplete style tags:
autocomplete style tags

antoinetooley’s picture

Hi,

I am getting this error when using this patch with an authenticated user:

Recoverable fatal error: Method DatabaseCondition::__toString() must return a string value in realname_query_era_query_alter() (line 454

Any ideas?

It works great with the user number 1 which I love

antoinetooley’s picture

Hi again,

I figured out the problem, which was to add an is_string check:

foreach (element_children($where) as $key) {      
  if (is_string($where[$key]['field']) && $where[$key]['field'] == 'users.' . $label_column) {
      unset($where[$key]);
  }    
}

I hope that helps someone.

Thanks!

Derimagia’s picture

Awesome thanks for the feedback. I'll fix the patch when I have some time. I haven't looked into this for a while, what is adding a non-string to it? Sounds like a sub condition is being added somewhere.

jalpesh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.42 KB

I agree with @Derimagia on comment #5, where it is good to have support of other module. I have update the path as per suggestion in comment #12.

Status: Needs review » Needs work

The last submitted patch, 14: realname-entity-reference-autocomplete-2572691-6.patch, failed testing.

The last submitted patch, 14: realname-entity-reference-autocomplete-2572691-6.patch, failed testing.

The last submitted patch, 14: realname-entity-reference-autocomplete-2572691-6.patch, failed testing.

The last submitted patch, 14: realname-entity-reference-autocomplete-2572691-6.patch, failed testing.