Example of Form API Element to define an entity reference field
Autocomplete field once displayed on the UI

This module defines a new form element type, called "entityreference", that allows developers to add autocomplete fields to forms, so that users can reference any entity in the same way they would do through an Entity Reference field.

It supports:

  • Filtering by Entity type (mandatory).
  • Filtering by bundle (Any number of them).
  • Filtering by any property of the Entity.
  • Filtering by field values for any field of the Entity.
  • Limit to a maximum number of referenced entities (optional).

For an example of usage, see the pictures attached, or check the README.txt file.

Modules with similar features:

  • Entity Reference: Usable only for fields created through core's Field UI, not for fields in custom forms.
  • Entity Autocomplete: Same functionality as this module, but offers fewer options. Also, it has a small security issue related to access control.

Drupal 8

There are no plans of a D8 version of the module, since Drupal 8 core ships its own entity_autocomplete element. A port might be considered if it adds substantial benefits over the core element (such as advanced filtering or search options).

This module has been written by Salvador Molina (@salva_bg).

Supporting organizations: 

Project Information

Downloads