5

I am attempting to get a taxonomy reference field select widget that shows a list of taxonomy terms, including some extra data from their fields. I have attempted to use the "Reference method" = "Views: Filter by an entity reference view" and then select an entity reference view I created, then in my entity reference view I have done the following:

enter image description here

However, this gives me only the taxonomy term name despite the settings indicating it might show all the fields inline ("Note: In 'Entity Reference' displays, all fields will be displayed inline unless an explicit selection of inline fields is made here.").

enter image description here

  • The same thing happens to me using references to users and content. I filled a bug report at drupal.org. You can find it here. – user60700 Apr 27 '16 at 6:11
  • for future reference, that issue was closed as duplicate, current issue is: drupal.org/node/2174633 – Andre Baumeier Aug 30 '16 at 14:28
  • For future reference: this is a core bug. Work is being done here: drupal.org/node/2174633 – Andre Baumeier Aug 30 '16 at 14:28
4

You can't at the moment.

See \Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::getReferenceableEntities(), it just uses the view to get the results and then calls $entity->label(). Which means you have no way to override that.

Which means that if you want this, you need to provide your own plugin. You can either subclass from ViewsSelection and still a view, or just extend from the default and override that method.

Might also be worth opening a feature request, I've already had this use case multiple times, and a new checkbox or option somewhere would be a nice, backwards compatible way to introduce this feature in a minor release.

2

The module Entity Reference Views Select supports additional fields in select lists and checkboxes when selecting entities in an entityreference field. We've used it successfully with ECK entities.

0

There might be a way to get around this, but it also has restrictions as indicated in this issue filed by me : https://www.drupal.org/node/2841330#comment-11854353

In other words, write your own display handler to deal with the result of an entityreference view result.

The webform_references developers have done that but as you can see in my issue, they also delegate their webform select option theming to the views rendering outcome. Where in my opinion (see second comment) it should be the responsibility (or choice for that matter) of the one who is requesting the entity reference view. In other words, use the views_get_view_result() function instead of $view->execute_display().

0

There is a working patch for this: View output is not used for entityreference options

protected by Community Jun 5 '17 at 5:59

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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