Learn how to alter the outputs from an entity reference field to show more than just the title.
Typically, only the titles appear when you search for items to reference. This is usually sufficient. However, when your content has many similar titles, using the autocomplete widget can be confusing due to the likeness of the results.
Fortunately, the Views module allows you to modify what appears in the autocomplete widget, so you don't need any extra modules.
Here are the steps to change the autocomplete outputs. Instead of just the "Title", we'll display "Title - Content Type - Created Date".
Set Up View with "Entity Reference" Display
➜1️⃣ Navigate to Structure, then Views, and create a new View. Click on "Add" next to Default and include an "Entity Reference" display.
➜2️⃣ Click on Settings next to "Format: Entity Reference list" and choose "Content: Title" as the "Search fields".
➜3️⃣ Add the "Content type" and "Authored on" fields to the view. You can add any field you want to appear in the autocomplete outputs.
➜4️⃣ Save the view.
Adjust Entity Reference Field
➜1️⃣ Edit an entity reference field, select "Views: Filter by an entity reference view" from "Reference method," and choose the view you created.
Note: If you can’t see your display, ensure that you’ve created an "Entity Reference" display in your view.
➜2️⃣ When you use an entity reference field, you should see the modified results.
We hope you find these steps helpful in customizing your autocomplete results. I sometimes forget just how powerful and flexible Views can be. Let me know in a comment below if you want more content about Views.
Watch video Customize Entity Reference Autocomplete Results in Drupal using Views online without registration, duration hours minute second in high quality. This video was added by user WebWash 08 July 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 193 once and liked it 13 people.