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.

Issue fork drupal-3545295

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

qiutuo created an issue. See original summary.

hemuvyas97’s picture

Assigned: Unassigned » hemuvyas97

Working on it.

cilefen’s picture

quietone’s picture

Version: 11.2.x-dev » 11.x-dev
Assigned: hemuvyas97 » Unassigned

Hi, 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.

vivek panicker’s picture

Thank you @quietone for the information. I'll make sure to pass it on to my team so that they abide by the community standards.

hemuvyas97’s picture

Issue summary: View changes
hemuvyas97’s picture

Issue summary: View changes
hemuvyas97’s picture

Status: Active » Needs review
StatusFileSize
new53.41 KB

After making the changes in FieldableEntityNormalizerTrait.php, I was able to create entity for ECK with RESTful POST method.

curl --request POST "http://drupal11-core.lndo.site/entity/books?_format=json" \
  --header "Content-Type: application/json" \
  --header "Accept: application/json" \
  --header "X-CSRF-Token: 7pfuSVeLMyavQhCQ3WpkZ2yYLeiR-VDVnJwXI3hXNAQ" \
  --user Admin:admin123 \
  --data '{
    "type": [{ "target_id": "novel" }],
    "title": [{ "value": "The Harry Potter" }]
  }'
smustgrave’s picture

Status: Needs review » Needs work

Left some comments on the MR.

hemuvyas97’s picture

Checking the comments and fixing the MR accordingly.

hemuvyas97’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.