Problem/Motivation

The D7 entity reference views selection did a) filter and b) provide the text for select options. (and c) grouping but that's a followup).

Most of this got lost in the D8 port, so in D8 the entity reference views selection field widget only filters, but always uses the referenced entity's label.

This is a huge loss and in contrast to UI texts. Also see @berdir's SO answer.

So story: As a sitebuilder i want to adjust the labels displayed for referenced entities via the views selection.

Proposed resolution

Re-add the functionality to use views' rendered output for the entity reference selection.
For BC reaons, add an option for that.

Remaining tasks

Codeit.

User interface changes

Add said option.

API changes

Maybe additions.

Data model changes

Entityreference field config: said option added.

Comments

axel.rutz created an issue. See original summary.

geek-merlin’s picture

Title: Entity refrence views selection does not use fields » Entity refrence views selection does not use views output
geek-merlin’s picture

Component: entity_reference.module » views.module

Code has gone to views.module:
\Drupal\views\Plugin\EntityReferenceSelection\ViewsSelection::getReferenceableEntities

  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $display_name = $this->getConfiguration()['view']['display_name'];
    $arguments = $this->getConfiguration()['view']['arguments'];
    $result = [];
    if ($this->initializeView($match, $match_operator, $limit)) {
      // Get the results.
      $result = $this->view->executeDisplay($display_name, $arguments);
    }

    $return = [];
    if ($result) {
      foreach ($this->view->result as $row) {
        $entity = $row->_entity;
        $return[$entity->bundle()][$entity->id()] = $entity->label();
      }
    }
    return $return;
  }
anruether’s picture

geek-merlin’s picture

Status: Active » Closed (duplicate)

Yup, thx!