![]() Have you been getting frustrated searching D.O for an answer? Are you weeding through Stack Overflow or Drupal Exchange posts for this common use case? By using the Views module, you can customize the autocomplete results to whatever is required, and this will help your editors on your Drupal site.Are you trying to add a block of related content to a node page in Drupal? Do you want to display other nodes which share terms with the currently displayed node? SummaryĮntity reference fields are powerful but become difficult to use if you have a lot of content with similar titles. Now when you search for content in the entity reference field you should see the title, content type and created date. Note: If you can’t see your display then make sure you’ve created an “Entity Reference” display in your view. Then from “View used to select the entities”, select the display we created. From the “Reference method” drop-down select “Views: Filter by an entity reference view”.Ĥ. Configure Entity Reference to use ViewsĬreating the view is the first step you need to configure the entity reference field to use the new view.ģ. Now the fields should be spaced out nicely. To do this, click Settings on the Show row in Format.Īdd a space before and after the dash in the separator field. It’s a good idea to add a space at the beginning and end of the dash so it’s readable. In the above image you will see that the fields a separated by a dash (-) but there’s no space between them. In the Preview section, you should see something like this: Spacing Between Fields Note: You can configure the date anyway you want.Ĩ. Select “HTML Date Format” from “Date format”. Click on Add again and this time search for “Authored on”.ħ. Click “Add” in the fields section and search for “Content type”.Ħ. If you don’t make the above change you’ll see this error:ĥ. Click on Settings in the Format area and check “Content: title”. Click on Add in the Displays section and click on “Entity Reference”.Ĥ. In this example we’re using referencing other content types, such as pages and articles, so we’ll leave Content selected.īut if you’re referencing taxonomy terms, then you’ll need to select “Taxonomy terms” from the Show drop-down.ģ. Add “Related autocomplete” as the View name (this can be anything).įrom the “View settings” section select the correct entity type from the Show drop-down. Go to Structure, Views and click on “Add view”.Ģ. ![]() To customize the autocomplete we’ll need a View.ġ. It’ll return the following: Title - content type - date Customize Autocomplete using Views Let’s modify the returned results to display not just title, but content type and created date. You can see that both are being returned. In the example above I have two article starting with “How to Build”. Go to the Article form and search for content in the Related field. From the “Reference type” section, select Article and “Basic page” from “Content type”. Select Unlimited under “Allowed number of values” and click on “Save field settings”.Ĥ. ![]() Click on “Add field” and select Content under Reference and add Related as the Label then click on “Save and continue”.ģ. Go to Structure, “Content types” and click on “Manage fields” on the Article row.Ģ. Note: If you’ve already created an entity reference field, skip this section.ġ. Editors will be able to reference a page or article using the field. Let’s start by creating an entity reference field called Related on the Article content type. You do not need to download any extra modules. Make sure you have the Views and Views UI module installed. Edit the entity reference field settings and configure the “Reference method” to use the created view display.įor a more detailed explanation, continue reading. Create a View with the “Entity Reference” display.Ģ. To customize the autocomplete results, complete the following steps:ġ. Configure Entity Reference to use Views.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |