Remove entity button not showing in Complex Inline Entity Form after upgrading to 3.x from 1.x

Created on 23 August 2024, 3 months ago

Problem/Motivation

After upgrading to 3.x from 1.x, Remove button in Complex Inline Entity Form is not being displayed in some cases.

After investigation, I found out that the issue originated from changes introduced in 🐛 Memory allocation error Fixed

Previously, countReferenceableEntities() was used to determine the count which returned the correct total count but was throwing memory issue for some users.
The changed code uses getReferenceableEntities(NULL, 'CONTAINS', 2). But this function returns list of entities grouped by Bundle name array key. Ref: https://git.drupalcode.org/project/drupal/-/blob/10.3.2/core/lib/Drupal/...
Hence, count($handler->getReferenceableEntities(NULL, 'CONTAINS', 2)) will always return 1 when only one entity bundle is involved and it will fail.

The below xdebug console SS should paint a clear picture.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇮🇳India Supreetam09 Kolkata

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

Comments & Activities

  • Issue created by @Supreetam09
  • 🇮🇳India Supreetam09 Kolkata

    We need to handle 2 cases:

    • When the count of type of entity bundles involved is more than 1, then current code will work, as count($handler->getReferenceableEntities(NULL, 'CONTAINS', 2)) will return 2
    • When the count of type of entity bundles involved is equal to 1, we need to count the items inside bundle array key. Ex: in my case, the count should have been of count($handler->getReferenceableEntities(NULL, 'CONTAINS', 2)['gallery_item'])
  • 🇮🇳India Supreetam09 Kolkata

    There is some SSH error, I can't create MR.
    Adding a patch instead for the fix.

  • Status changed to Needs review 3 months ago
  • 🇮🇳India Supreetam09 Kolkata

    An even simpler patch.

Production build 0.71.5 2024