1

In one of my "add node" form, I would like to display the 'name' field of referenced content type rather than the title.

Let's say, Content type 'Car' contains a field called 'owner' which is entity ref to content type 'person'. 'person' has a unique title but also has a field called 'name'.

While displaying to the user '/node/add/car' form, I like to give the user a 'select list' for the field 'owner'. I want to populate this field with the names of the 'person' nodes in the system and not their 'title'.

So in 'manage form display' of the content type 'car', I used 'select list' and in the 'manage display', selected for the 'owner' field, format of "rendered entity". But this displays only the title in the dropdown list in 'add/node/car'.

When that did not work, I tried using the new d8 feature,'display mode'. I created a display mode called "nameview" and created a "nameview" display for content type 'person' which displays only the field 'name'. I then used that view mode in the "manage display" for 'Car'. Still I get only the titles in 'add/node/car'.

What am I doing wrong? or is this a bug in d8?

1

What you configure in Manage display has nothing to do with what is shown in the form. That's not how it works.

You can do this using a view. In field settings, configure it to use a view show possible values and then configure that view to show the values you want to see.

  • But in a view, how do I get user input for the rest of the fields? – AjayR Dec 14 '15 at 17:17
  • Ajay, I don't understand your comment in the context of your question. Either there's an important part of your requirement missing from your original question, or you've not understood what Berdir means. – Jonathan Dec 14 '15 at 19:54
  • What you need to is this: 1) Create a view with an "entity reference display", showing the "Person" content type and containing just the field "Name" that you want; 2) in the field settings for the entity reference field "owner", choose the Reference method "Views: Filter by an entity reference view" instead of "Default"; 3) select the view you created in step 1 as the reference view to use. You don't need to touch the "manage form display" or "manage display" stuff. – Jonathan Dec 14 '15 at 19:54
  • Thanks Berdir and @Johnathan for clarifying it further. Now I think I get what I need to do. – AjayR Dec 14 '15 at 22:03
  • 1
    Unfortunately I have a different error now . When I click on Add->"entity reference" in "Views..edit" to create a new display, It gives a msg "Display "Entity Reference" needs a selected search fields to work properly. See the settings for the Entity Reference list format." but it does not bring up anything when I click on 'settings' and there is a message in the log which says "User error: "preview" is an invalid render array key in Drupal\Core\Render\Element::children() ". So I guess I am stuck for the moment while I check around to see if there is solution to this. Thanks again – AjayR Dec 14 '15 at 22:04
0

This is actually not possible with Entity Reference views in Drupal 8, but will be soon. See View output is not used for autocomplete display.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.