as with the patches for all the other user reference modules.. the autocomplete should search on realnames, not usernames (since in most sites we dont know a user's username).

Comments

liquidcms’s picture

hmm.. a bit of a pita to patch for this since the module uses entityfieldquery for its db search and there is no way to do a join (to the realname table) with EFQ.. ughh

slv_’s picture

Status: Active » Postponed

As much as I'd like that feature, doing it cleanly means simply adding support for more customizable queries. While I've something in mind for that already, I lack the time to do that right now, and I'm not sure I'll be able to pick this up anytime soon :(.

slv_’s picture

Status: Postponed » Closed (works as designed)

In fact, I think I'm going to close the ticket rather than postponing, since this will be allowed when what i mention is in place, so no point of keeping it as something separate, which might be misleading.

However, you can still achieve what you want, since, even though there's no alter hook that gets the string passed by the user, it's relatively simple to inject your custom query there. I suggest you use hook_menu_alter() to override this entry:

function entityreference_autocomplete_menu() {
  $items['entityreference_autocomplete/autocomplete/%/%entityreference_autocomplete_bundles/%'] = array(
    'title' => 'Entity Reference Element autocomplete callback',
    'page callback' => 'entityreference_autocomplete_autocomplete_callback',
    'page arguments' => array(2, 3, 4),
    'access arguments' => array('access content'),
    'file' => 'includes/autocomplete_callback.inc',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

In there, replace the "page callback" for some callback of your own. Then in that callback, check for the entity type, and if it's user, you can write your own code (or simply delegate logic to a copy of the original callback function, replacing just the bits you need). If it's not a user, then you can just delegate to the original entityreference_autocomplete_autocomplete_callback() function.

While it's a bit hacky, it's a quick way to get around the limitations of the 7.x-1.x version for what you are trying to do.

Best regards.

liquidcms’s picture

thanks for the idea.. that should work.

Derimagia’s picture

Status: Closed (works as designed) » Needs review
StatusFileSize
new1.97 KB

Adding patch for this. I added a tag to the query so that we can alter for realname.

Derimagia’s picture

Status: Needs review » Needs work

Patch still needs some work to work 100% but it's pretty easy to implement. I'll continue to work on it.

Derimagia’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB

Adding new patch

dpliscoff’s picture

Patch #7 over 7.x-1.8+2-dev and can confirm it works.

slv_’s picture

Hi all,

Not too sure about adding this one, although the approach looks certainly great. I don't mind adding the tags to allow for query alters, but I don't think this module should cope with logic to alter the query based on the data model from another module.

Derimagia, do you happen to know the realname maintainer, or would you mind opening an issue to support entityreference autocomplete? Happy to add the tags, but the realname-specific logic should be in there, and not here.

Marking as needs work for now.

slv_’s picture

Status: Needs review » Postponed (maintainer needs more info)
Derimagia’s picture

Opened up a ticket here: https://www.drupal.org/node/2572691

Understand not wanting to have the query alter in this module, but if we can add the tags then that would be useful for other reasons as well.

slv_’s picture

Sure, of course. Would you mind re-rerolling a patch just with that?

Also, this:

$query->addMetaData('era_search', $last_label);

Can be:

$query->addMetaData('era_search_string', $last_label);

Just to make it obvious it is the search string entered by the user?

Thanks a lot for taking the time to open the other issue as well.

Derimagia’s picture

StatusFileSize
new1.13 KB

Attached is the new patch

  • slv_ committed 271a359 on authored by Derimagia
    Issue #2353169 by Derimagia: entity reference for users should use...
slv_’s picture

Thanks for that.

Pushed to --dev branch. Rolling out a new stable release now. Thanks!

Will close for now, but feel free to reopen if the realname module doesn't consider adding the other part to his module.

slv_’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)