EntityResourceBase::createCollectionDataFromEntities collapses results by $entity->id()

Created on 18 March 2021, over 3 years ago
Updated 15 March 2024, 3 months ago

Problem/Motivation

In a multilingual result set, a single entity can be represented multiple times.

Steps to reproduce

  1. Setup a multi-language Drupal instance.
  2. Create ~35 multi-language content nodes. Translate ~15 of those nodes.
  3. Create a JSON:API Resource endpoint; like with JSON:API Search API of that content.
  4. Access that JSON:API endpoint for that content
  5. Observe results
  6. The resulting set should return 50 items. But the actual result will be less; w/ the proper "meta: count" of the total results

Here's a comparison of the resultset from my JSON:API Search API query set vs. the collapsed result set returned from Drupal\jsonapi_resources\Resource\EntityResourceBase::createCollectionDataFromEntities. The result set count should match the query set count.

Proposed resolution

Drupal\jsonapi_resources\Resource\EntityResourceBase::createCollectionDataFromEntities keys its results by $entity->id() which collapses results by the last instance of an entity in the query set.

Instead should key its results by the $delta of the passed-in $entities; making no assumptions about the dataset.

Remaining tasks

[patch inbound]

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States freality

Live updates comments and jobs are added and updated live.
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