Missing label with entity reference

Created on 31 March 2025, 9 days ago

Problem

The "label" object variable in the row results is missing when using an entity reference view display.

Steps to reproduce

  1. Import the sample view that defines a basic config entity reference view that lists webforms that match.
  2. Change the stock Webform content type (or define a new one) webform field to use the config view entity reference.
  3. Try to create Webform content type. This should cause an error that indicates the "label" is missing.

Proposed resolution

It does not appear that the label is actually used and is not provided in this case in the file: config_views/src/Plugin/EntityReferenceSelection/ConfigViewsSelection.php

  public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
    $entities = [];
    if ($results = $this->getDisplayExecutionResults($match, $match_operator, $limit)) {
      foreach (Element::children($results) as $id) {
//        $entities[$results[$id]['#row']->type][$results[$id]['#row']->id] = $results[$id]['#row']->label;
        $entities[$results[$id]['#row']->type][$results[$id]['#row']->id] = $id;
      }
    }
    return $entities;
  }

I was not able to track down where the row results would be created with the label. Using $id instead seems to work just fine for entity references. The alternative would be to test if the label is missing and only use $id in that case.

πŸ› Bug report
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bwong

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024