I'm trying to create a Entity Reference autocomplete field against users. Instead of using user names, I'd like to use another field in the user entity ("field_full_name") to search against. (I've already solved the issue of altering the returned user to display the correct field name - using hook_user_format_name_alter)
I did manage to get user searches working by user name by changing "target_type: node" to "target_type: user", but I'm a bit baffled as to how:
selection_handler: default
selection_settings: { }
are intended to work if I want to have a non-standard user search.
I did manage to get a manual form element to work via the views_autocomplete_api module, but it felt like quite a hack. Ideally I'd like to be able to use a entity reference view to be able to pull up the data, but at this point I'm about ready to write my own selection handler.
I'm prepared to do the legwork on this problem and document the solution if it's left as an exercise to the reader, but I'd like to get nudged in the right direction. Can this be done with just YAML Form and views, or do I need to build on my own selection_handler, or is there another solution I'm not considering?
Thanks in advance!
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | entity_autocomplete-2810199-6.patch | 1.75 KB | jrockowitz |
| #5 | Screenshot from 2016-10-03 12-16-34.png | 127.54 KB | trevorbradley |
| #5 | Screenshot from 2016-10-03 12-15-12.png | 142.53 KB | trevorbradley |
Comments
Comment #2
jrockowitz commentedYou should be able set up an Entity reference views display and use it. See https://www.ostraining.com/blog/drupal/entity-reference-view/
Are you using the YAML Form UI? If you use the UI it should correctly setup the selection handler and settings.
Comment #3
trevorbradley commentedI am using the YAML Form UI. I think I may see my confusion. I was using Entity Autocomplete, rather than Entity Select.
I see the "Reference Method" pulldown in the "Entity Reference Settings" pulldown in the "Entity Select" element, but not in "Entity Autocomplete" element. The entity reference view appears to work just fine in Entity Select.
"Entity Autocomplete" does not have an "Entity Reference Settings" pulldown. It also only appears possible to change what you're referring to using the "Custom Settings" section.
If I look at the Source (YAML) tab, and manually copy the entity_select parameters into entity_autocomplete's custom parameters... I can get it to work, and it works great!
It looks as if Entity Reference Settings is missing from Entity Autocomplete in the YAML Form UI. It may be time to flip this to a feature request.
Comment #4
trevorbradley commentedComment #5
trevorbradley commentedAdded corroborating screen shots. Entity Autocomplete doesn't have a "Entity Reference Settings" submenu, but Entity Select does.
Comment #6
jrockowitz commentedComment #8
jrockowitz commentedFixed! Please download the latest dev release.
Comment #9
trevorbradley commentedTested. Looks good to me. Nice work jrockowitz!