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.
Issue fork display_builder-3570382
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 #2
pdureau commentedComment #3
pdureau commentedImplementing ContentEntityTypeInterface means supporting those interfaces:
ContentEntityInterfaceitself, 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 withnode_id,source_id,sourceandthird_party_settings), so extending the UI Patterns Source field type and consolidating the logic there\Drupal\Core\Entity\TranslatableRevisionableInterfacewe 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 methodsThe most important is to keep the storage logic:
Comment #6
pdureau commentedComment #7
pdureau commentedHello, 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.
Comment #9
mogtofu33 commented