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 (there is a nissue for that: #3042467: Support entities that are neither content nor config entities, but it may be easier/faster to adapt our codebase.

Command icon 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

pdureau created an issue. See original summary.

pdureau’s picture

Title: Compatoibility with JSON API » Compatibility with JSON API
pdureau’s picture

Issue summary: View changes

Implementing ContentEntityTypeInterface means supporting those interfaces:

  • ContentEntityInterface itself, only one method ::getBundleEntity() which can be returning NULL
  • \Traversable: nothing to do?
  • \Drupal\Core\Entity\FieldableEntityInterface: annoying but we can consider each node as a field with node_id, source_id, source and third_party_settings), so extending the UI Patterns Source field type and consolidating the logic there
  • \Drupal\Core\Entity\TranslatableRevisionableInterface we are already planning to do #3562989: Implements RevisionLogInterface for Instance entity and the translation part may be related to #3555110: Symmetric translation
  • \Drupal\Core\Entity\SynchronizableInterface: only 2 easy methods

The most important is to keep the storage logic:

  • the saved "step" is directly retrieving data from the content or config entity (it works like that since December 2025 AFAIK)
  • the other "step" is stored in a volatile way. Today it is the State API, it can become the normal content entity storage, using the Node field type, if it is faster (while keeping the index in the State API).

prasanna-venkat changed the visibility of the branch 3570382-compatibility-with-json to hidden.

prasanna-venkat changed the visibility of the branch 3570382-compatibility-with-json to active.

pdureau’s picture

Title: Compatibility with JSON API » Fatal: Compatibility with JSON API
Priority: Normal » Major
pdureau’s picture

Assigned: Unassigned » pdureau

Hello, we are accelerating the release of beta2, and we must move faast.

Prasana, I have seen you ave created the fork already, without assigning the issue to you or pushing anything, so i take the ownerhsip of the MR and i will try to propose a quick fix to avoid the fatal.

mogtofu33’s picture

Assigned: pdureau » Unassigned
Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mogtofu33 committed a38f602b on 1.0.x authored by pdureau
    fix: #3570382 Fatal: Compatibility with JSON API
    
    By: pdureau
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.