Problem/Motivation
EntityResourceBase::createCollectionDataFromEntities assumes all the entities would be of same entity type and leading to data loss.
If there's an entity-oriented JSON:API Resource which tries to render entities of multiple entity types then EntityResourceBase::createCollectionDataFromEntities overrides the data for one entity with other if the entity ids match.
Steps to reproduce
- Install this module along with jsonapi_search_api module.
- Setup a search index that tracks multiple entity types e.g. nodes and users/comments etc.
- Create 2 nodes and 2 comments, at least one node and user entity should have same id.
- Try accessing the json api route of the index.
- See that the data for node is getting overridden by the user entity(or vice versa, whichever comes later.)
Proposed resolution
EntityResourceBase::createCollectionDataFromEntities should either use entity uuids to track the entity resource data or use "{entity_type}:{entity_id}" as the identifier. Currently it's using {entity_id} which causes the override.
Remaining tasks
User interface changes
NA
API changes
Data model changes
Issue fork jsonapi_resources-3565859
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
mglamanThanks!