Have you been frustrated with the default search key (title) on an entity reference field in Drupal?
For example you have 2 nodes which have the same title but different contents, and now you don't know which is which cause of the lacking infromation in the autocomplete dropdown.
There is actually a solution for this! And it doesn't need a custom module nor for you to code. This function comes within Drupal 8's core. And here are the steps on how to alter/override the entity reference form field.
Firstly, you'll need to create a view which filters the same content type your entity reference is targeting.
In this example, the field I created is an entity reference targetting the "Basic Page" content type. So I will need to create a view with the same filter (VIEW SETTINGS> OF TYPE> BASIC PAGE)
Second step, is to create an entity reference display inside the view like so
Once you have created the entity reference display, you can now override the search key, autocomplete and other properties the entity referece field form has. For our example, we want to display the ID of the node. We simply add the field as follows.
You can modify how the autocomplete looks like by adding each field! Or by rewriting text.
Lastly we need to edit the field to make the reference method point to the view we created. We go to the content type and click "manage fields" and then we edit the field which is used as entity reference like so.
Don't forget to hit save!
Now let's save the view and go back to the form!
Now you can see that even with the same title, you won't be confused cause you have added the ID.