Hi,

I don't know if it is a bug, but when I send GET request to my custom entity, I received an error 500.

The watchdog entry :

Symfony\Component\Routing\Exception\RouteNotFoundException : Route "entity.MY_ENTITY_TYPE.canonical" does not exist. dans Drupal\Core\Routing\RouteProvider->getRouteByName() (ligne 191 de /Applications/MAMP/htdocs/drupal8/core/lib/Drupal/Core/Routing/RouteProvider.php).

It's worry because one of my custom entity without bundle works perfectly.
But, this entity is configured to accept bundles. If I add only one bundle, it's OK. But when I add another bundle and I try to access to one entry of this new bundle via REST, Drupal save this error.

My endpoint :
http//mydrupal.env/MY_ENTITY/3?_format=json

Thanks,

Anthony (french who have bad english)

CommentFileSizeAuthor
#6 rest.settings.yml704 bytesanthony thomas

Comments

anty56 created an issue. See original summary.

anthony thomas’s picture

Issue summary: View changes
wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

What's the name of your entity type?

Note the error says MY_ENTITY_TYPE and the URL says MY_ENTITY.

anthony thomas’s picture

My entity type : training_entity_type
I have 2 bundles : learn and serious_game

In fact, I don't understand this error, because there is a reference to entity type URL.

wim leers’s picture

Can you export your rest.settings configuration and post it?

anthony thomas’s picture

StatusFileSize
new704 bytes

Hi,

now it is league the name of my entity.

Thanks.

wim leers’s picture

So are you doing GET REST requests to http://mydrupal.env/league/3?_format=json now then?

anthony thomas’s picture

Yes, have just a different endpoint because I don't edit default URI suggest by Drupal Console when I generated the custom entity.

http://mydrupal.env/admin/structure/league/3?_format=json

Error is the same :

Symfony\Component\Routing\Exception\RouteNotFoundException : Route "entity.league_type.canonical" does not exist. dans Drupal\Core\Routing\RouteProvider->getRouteByName() (ligne 191 de /Applications/MAMP/htdocs/drupal8/core/lib/Drupal/Core/Routing/RouteProvider.php).

wim leers’s picture

Title: Wrong result on GET request (custom entity type) » Problems with entity route auto-generation
Component: rest.module » entity system
Status: Postponed (maintainer needs more info) » Active
Related issues: +#2350503: Add route generation handlers for entities

Eh, that's not at all REST, that's just the default route in general. It looks like your problem is in Entity API, in how routes are auto-generated. See #2350503: Add route generation handlers for entities.

I should've noticed that sooner. Moving to the right component.

dietr_ch’s picture

In case you still have this problem (or for future readers): Drupal Console adds a canonical link path to your generated entity type config entity, even though the route for the canonical path doesn't exist. You need to remove the canonical link from the "links" collection in the @ConfigEntityType annotation.

sylvain lavielle’s picture

@dietr_ch: thank you so much. that's it !

berdir’s picture

Status: Active » Fixed

Sounds like that's a bug in drupal console then. Marking this as answered, throwing the exception is the right thing to do for core, if anything, it could maybe explain the problem a bit more.

Status: Fixed » Closed (fixed)

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