How do I override the look up on an entity reference autocomplete field? I would like to limit the look up to nodes of a certain type that have been created by the user that is creating the current node.


The Entity Reference module integrates with the Views module in a few ways. One of these is a new display called Entity Reference.

Create a view, and filter it to your needs. Then, add a new Entity Reference display. Configure this.

Then, on your content type(s), edit the entity reference field. Make sure you are using the AutoComplete widget. You should see a fieldset called Entity Selection. Change this from "Simple (with optional filter by bundle)" to "Views: Filter by an entity reference view". You should then see a dropdown appear which will have all of the views you have created that have Entity Reference displays. Pick your view and save.

Keep in mind, though, that views with large datasets can cause dramatic performance problems with autocomplete fields.

| improve this answer | |
  • It is possible to set this up instead with autocompletepath setting on the field, and a hook_menu() callback? – Andrew Welch Jul 9 '13 at 17:49
  • The entityreference_autocomplete widget is a normal FAPI textfield with #autocomplete_path (see entityreference_field_widget_form(). In theory I guess you could form_alter and change the path to something you define yourself, but I have never tried this. – mpdonadio Jul 9 '13 at 17:59

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.