My Goal:
I want to create a customized entity_autocomplete
form field to better fit my needs compared to the default one - making some modifications to the HTML and JS that's being used, as well as how submissions are handled.
Specifically, I want to do something like this but I need more control over the backend, and everything...
What Drupal can do:
Drupal's default entity autocomplete already lets the user type 2 letters, and it finds all entities that contain these 2 letters.
My Problem:
Unfortunately I have trouble figuring out how to use the existing "search feature" if you will call it that.
Some Considerations:
I looked into using search API, but this was similarly overwhelming. Considering that this functionality I'm looking for is already built into Drupal, I figure I can just re-implement it, without any additional modules, right? Really, I'm just re-designing the UI. And even if I need to beef it up in the future with a faster, resource saving search engine, I can just replace that aspect of my module/controller. (If someone can point out how to use Search API to do what I need, I'd be happy to listen)
What I've done so far:
I have already created my own custom route that points to a JSON controller which will accept the search parameters.
Based on all my research I figured I need to add use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
to the top.
I see that DefaultSelection::getReferenceableEntities
seems to do exactly what I need it to do.
However, the constructor for this class has 9 different parameters, many of them classes which I know nothing about.
But there is a create
method, which apparently allows you to inject configuration data, but also it requires a ContainerInterface
.
So here's where I'm lost...
How exactly do I make use of DefaultSelection::getReferenceableEntities
in my custom controller?
Chosen
and/orSelect2
JS libs, that turn normal select fields into your screenshot. – Hudri Sep 7 '20 at 19:12