Loading referenced entities does not take bundle (type) into account

Created on 23 September 2021, almost 3 years ago
Updated 2 March 2023, over 1 year ago

Problem/Motivation

When the same field is re-used in different entity bundles, the "loadReferencingEntitiesOfType" method returns duplicate entries (list is added for each entity bundle the field is re-used in.

Steps to reproduce

  1. Create a node bundle A with field_tags referencing "tags" vocabulary
  2. Create a node bundle B with field_tags referencing "tags" vocabulary
  3. Create a node bundle C with field_tags referencing "tags" vocabulary
  4. Create a node in any bundle referencing tag 1
  5. Execute \Drupal::service('term_reference_change.reference_finder')->loadReferencingEntitiesOfType($tag1, ['bundleA', 'bundleB', 'bundleC'], 'node')
  6. $referencingEntities contains our node 3 times

Proposed resolution

The method is already looping over the bundles but not filtering on it. Solution is to add the $bundle_name as a key in the loop, and filter the entity query on type.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium KevinVanRansbeeck

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024