0

By 'trim' I mean that I want to restrict the usernames returned according to some criterion. For example, if I enter 'S' into my user reference field, I want the drop-down list to contain all usernames begining with 'S' and where, for example, the users favourite color equals 'Red'. 'Favourite color' would be a field added on to the user entity.

My first idea is to use hook_query_alter to add a condition clause to the relevant query in user_reference module, but I'm not sure if this is possible. Has anyone done something like this before?

Thanks

1 Answer 1

0

You can use hook_form_alter() to provide your own autocomplete path. After that you can code it just like if you were creating brand new autocomplete field. Examples for developers module contains pretty solid autocomplete example, use it as a reference.

1
  • Thanks. I'm reluctant to replace what looks like a sophisticated autocomplete function, _user_reference_potential_references_standard, in user_reference.module. Do you think it would be bad practice to add a join and my extra condition to the query in _user_reference_potential_references_standard? The References module is not part of core, but I'm not sure if 'hacking' it is a good idea?
    – dbj44
    Commented Jun 3, 2013 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.