You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a custom content entity Music using generate:entity:content command with bundles support enabled. It will create two entity classes Music and MusicType
Create a bundle Rock. Add some content for Rock bundle.
Enable REST resource for Musicin configuration which will be something like /admin/structure/music/{music}.
Make a GET request with REST api like /admin/structure/music/1.
You will get error something like {"message":"A fatal error occurred: Route entity.music_type.canonical does not exist."}
Solution
As mentioned in this issue, this is happening because Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCanonicalRoute()requires view_builder to create a canonical url, which is missing from MusicType class.
If you manually add "view_builder" = "Drupal\Core\Entity\EntityViewBuilder" in handlers list of MusicType class, it works fine.
The text was updated successfully, but these errors were encountered:
tahirm
changed the title
[ *generate:entity:content* ] Missing view_builder handler for custom entity with bundles
[generate:entity:content] Missing view_builder handler for custom entity with bundles
Jan 24, 2017
Problem
When creating a custom entity with bundles support, you are not able to access entities through REST api.
How to reproduce
Steps to reproduce
Music
usinggenerate:entity:content
command with bundles support enabled. It will create two entity classesMusic
andMusicType
Rock
. Add some content for Rock bundle.Music
in configuration which will be something like/admin/structure/music/{music}
./admin/structure/music/1
.{"message":"A fatal error occurred: Route entity.music_type.canonical does not exist."}
Solution
As mentioned in this issue, this is happening because
Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider::getCanonicalRoute()
requiresview_builder
to create a canonical url, which is missing fromMusicType
class.If you manually add
"view_builder" = "Drupal\Core\Entity\EntityViewBuilder"
in handlers list ofMusicType
class, it works fine.The text was updated successfully, but these errors were encountered: