In order for the autocomplete to work, you have to extend EntityReferenceSelectionHandlerGeneric. The steps are simple:
- Create a file named:
EntityReferenceSelectionHandlerGeneric_ENTITYTYPE.inc and put it inside the module that creates the custom entity, inside a folder such as plugins. Replace ENTITYTYPE with the name of your custom entity. In my case, _student, as in EntityReferenceSelectionHandlerGeneric_student.inc
- In that file create a class that extends
EntityReferenceSelectionHandlerGeneric, as in:
class EntityReferenceSelectionHandlerGeneric_student extends EntityReferenceSelectionHandlerGeneric{
protected $label_key = 'name';
}
- Add this class to your module's autoload function, as in
/**
* Implements hook_autoload_info().
*/
function student_autoload_info() {
return array(
// Entity reference selection plugin.
'EntityReferenceSelectionHandlerGeneric_student' => 'plugins/EntityReferenceSelectionHandlerGeneric_student.inc',
);
}
- Clear caches.
In the class above, the trick is to provide a value for the property $label_key. This value must match the value for ['entity_keys']['label'] in your entity info.
In order for the autocomplete to work, you have to extend
EntityReferenceSelectionHandlerGeneric. The steps are simple:EntityReferenceSelectionHandlerGeneric_ENTITYTYPE.incand put it inside the module that creates the custom entity, inside a folder such asplugins. Replace ENTITYTYPE with the name of your custom entity. In my case,_student, as inEntityReferenceSelectionHandlerGeneric_student.incEntityReferenceSelectionHandlerGeneric, as in:In the class above, the trick is to provide a value for the property
$label_key. This value must match the value for['entity_keys']['label']in your entity info.