Drupal core already supports autocompletion of username fields. However is there a way to provide autocomplete for user's Display Name? Since this is a virtual field, a database query with % like cannot be performed.

One way I could think of accomplish this would be to save display name for each user in the user_data table, and set this storage with an event subscriber that reacts on account creation and account update. Once this field is available, it could then be used with database queries for autocomplete.

Interested to know if there is another way to do this.

  • It sounds like you've already answered your own question. There's no way to auto-complete this without a complex pre-computed solution.
    – Shawn Conn
    May 25 '19 at 2:48

I looked at realname module, which autocompletes the real name. Since realname stores the user defined DisplayName equivalent in the database, it can issue % LIKE queries and autocomplete on both username and realname.

I posted this question to see if there were other approaches, the realname module validates the proposed method as asked in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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