Can't replace selection in IEF complex form if allow new is not enabled

Created on 30 January 2024, 10 months ago
Updated 30 July 2024, 4 months ago

Problem/Motivation

I'm using IEF Complex forms on several content types to select a referenced entity with Entity Browser. All worked fine until RC 19 when the "remove" button disappeared from the form when an entity is selected. I determined this is because I have not also enabled "allow users to add new..." on the widget; this is because I find the UI confusing for my users when that option is enabled and, further, for User entities this function doesn't work. While I do get the "edit" button for the selected entity, I need to be able to allow users to replace the selection.

Steps to reproduce

Create a node with a reference field to another entity;
Set up a Complex IEF form that allows users to add existing entities but not create new entities;
Create a new node of this type and assign an entity to the reference field via IEF;
Note that you may only edit the entity, not remove it.

Proposed resolution

It appears that a check was added in 869ba998 to see if there are more than one referenceable entity before allowing the "remove" button to be enabled (see src/Plugin/Field/FieldWidget/inlineEntityFormComplex.php circa line 327). The problem is, Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities returns an array keyed by the entity type, so the check in the form isn't checking how many referenceable entities there are, but effectively is checking if there is more than one referenceable entity type. We need to check the inner key's results, not the root results.

I''l work up a patch for this.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tkiehne

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

Comments & Activities

Production build 0.71.5 2024