The entity types created using modules like ECK report this error because multiple entity types use the same class file, while the Jsonapi module does not have this error.
Drupal\Core\Entity\Exception\AmbiguousEntityClassException:Drupal\Core\Entity\EntityTypeRepository->getEntityTypeFromClass() in Multiple entity types found for Drupal\eck\Entity\EckEntity. (/www/wwwroot/web/core/lib/Drupal/Core/Entity/EntityTypeRepository.php The 83rd line).
#0 /www/wwwroot/web/core/modules/serialization/src/Normalizer/FieldableEntityNormalizerTrait.php(54): Drupal\Core\Entity\EntityTypeRepository->getEntityTypeFromClass()
#1 /www/wwwroot/web/core/modules/serialization/src/Normalizer/EntityNormalizer.php(39): Drupal\serialization\Normalizer\EntityNormalizer->determineEntityTypeId()
#2 /www/wwwroot/vendor/symfony/serializer/Serializer.php(240): Drupal\serialization\Normalizer\EntityNormalizer->denormalize()
#3 /www/wwwroot/web/core/modules/rest/src/RequestHandler.php(179): Symfony\Component\Serializer\Serializer->denormalize()
#4 /www/wwwroot/web/core/modules/rest/src/RequestHandler.php(67): Drupal\rest\RequestHandler->deserialize()
#5 [internal function]: Drupal\rest\RequestHandler->handle()
#6 /www/wwwroot/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#7 /www/wwwroot/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}()
#8 /www/wwwroot/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
Steps to reproduce
- Install ECK.
- Create two new entity type in ECK.
- Enable REST for those ECK entities
- Enable REST for books.
- Send a POST request:
curl --request POST "http://example.local/entity/books?_format=json" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "X-CSRF-Token: TOKEN" \
--user admin:admin \
--data '{
"type": [{ "target_id": "novel" }],
"title": [{ "value": "Test Book" }]
}'
Proposed resolution
Update EntityNormalizer::denormalize() and determineEntityTypeId() to:
- Use $context['entity_type_id'] if provided (normal case for REST routes).
- Otherwise, infer entity type from the submitted payload ($data['type'][0]['target_id']), by looking up which entity type owns that bundle.
- Only if both fail, fall back to getEntityTypeFromClass($class) (current default behavior).
This ensures REST can correctly resolve ECK entity types without breaking existing functionality for core entities.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | Screenshot from 2025-09-11 13-13-11.png | 53.41 KB | hemuvyas97 |
Issue fork drupal-3545295
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
hemuvyas97 commentedWorking on it.
Comment #3
cilefen commentedComment #4
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies. Thanks.
Also for Drupal core, it is preferred that contributors add a comment that they are working on an issue instead of assigning it to themselves. See Assigning ownership of a Drupal core issue.
Comment #5
vivek panicker commentedThank you @quietone for the information. I'll make sure to pass it on to my team so that they abide by the community standards.
Comment #7
hemuvyas97 commentedComment #8
hemuvyas97 commentedComment #9
hemuvyas97 commentedAfter making the changes in FieldableEntityNormalizerTrait.php, I was able to create entity for ECK with RESTful POST method.
Comment #10
smustgrave commentedLeft some comments on the MR.
Comment #11
hemuvyas97 commentedChecking the comments and fixing the MR accordingly.
Comment #12
hemuvyas97 commentedComment #13
smustgrave commented