Compatibility with JSON API

Created on 29 January 2026, 1 day ago

Problem/Motivation

Reported by Prasanna-Venkat: https://www.reddit.com/r/drupal/comments/1qp9w78/does_anyone_tried_insta...

JSON:API raise a fatal: "Only content and config entity types are supported"

because our Instance entity is neither a config entity nor a content entity. We did that because:

  • they are lighter than content and config entities
  • they have a custom storage

Proposed resolution

It is not as easy as extending ContentEntityBase and implementing the related interface:

@@ -53,7 +54,7 @@ use Drupal\ui_patterns\SourcePluginManager;
     'plural' => '@count instances',
   ],
 )]
-class Instance extends EntityBase implements InstanceInterface {
+class Instance extends ContentEntityBase implements InstanceInterface {
 
   private const MAX_HISTORY = 10;
 
@@ -338,7 +339,7 @@ class Instance extends EntityBase implements InstanceInterface {
   /**
    * {@inheritdoc}
    */
-  public function get(string $node_id): array {
+  public function get($node_id): array {
     $root = $this->getCurrentState();
     $path = $this->getPath($root, $node_id);
     $value = NestedArray::getValue($root, $path);

because being a content entity seems to trigger some Drupal mechanisms (like some magic around id property) and at least 8 of our PHPunit tests are failing in:

  • Drupal\Tests\display_builder\Kernel\InstanceAccessControlTest::testInstanceAccess
  • Drupal\Tests\display_builder\Kernel\InstanceHistoryTest::testSetSave
  • Drupal\Tests\display_builder\Kernel\InstanceHistoryTest::testGetUsers
  • Drupal\Tests\display_builder\Kernel\InstanceHistoryTest::testPostCreateWithPresentState
  • Drupal\Tests\display_builder\Kernel\PatternPresetTest::testGetSummary

Apigee module has the same issue by the way: https://github.com/apigee/apigee-edge-drupal/issues/625

Ideally, JSON API must skip the entity it is not able to handle without raising a fatal, but it may be easier/faster to adapt our codebase.

🐛 Bug report
Status

Active

Version

1.0

Component

Main / Misc.

Created by

🇫🇷France pdureau Paris

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