Support entities that are neither content nor config entities

Created on 22 March 2019, almost 6 years ago
Updated 12 September 2024, 3 months ago

Problem/Motivation

By design the module exposes resources for every entity type in the system. However, if a module contains an entity which does not implement ContentEntityTypeInterface or ConfigEntityTypeInterface, a WSOD/HTTP 500 error is thrown when the module is installed or the cache is rebuilt or JSONAPI resources are visited. The log contains the follow error:

LogicException: Only content and config entity types are supported. in Drupal\jsonapi\ResourceType\ResourceTypeRepository->getAllFieldNames() (line 285 of /var/www/html//modules/contrib/jsonapi/src/ResourceType/ResourceTypeRepository.php).

The same as a JSONAPI response:

title	"Internal Server Error"
status	"500"
detail	"Only content and config entity types are supported."

It might not be the usual use case to support non-content/config entities, but it would be nice to handle them in a way that doesn't break the system, like excluding them from resources and relationships.

Steps to reproduce

Enable either
* The entity_test module after you have applied the test_only patch from this issue or
* the Apigee Edge module or
* the Brightcove Video connect module

and visit the /jsonapi route.

Proposed resolution

MR3548 contains a fix that adds support for fieldable entities - basically it widens the content entity support. All previous existing tests in core proves that everything keeps working. It also introduces a very basic, best effort fieldable entity implementation in the entity_test module to prove whenever that module is enabled (it is enabled in several JSONAPI tests) the above describe problem occurs without the fix. (Dedicated tests for the fieldable entity are not even needed to prove the issue.)
🐛 Improve fieldable entity test/example class Active was opened as a follow up to improve and extend the fieldable entity implementation and maybe refactor/write more tests that leverages this new implementation.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

[#3343351]

Feature request
Status

Needs work

Version

11.0 🔥

Component
JSON API 

Last updated about 24 hours ago

Created by

🇺🇸United States Arlina

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

Merge Requests

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.71.5 2024