Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[generate:entity:content] Missing view_builder handler for custom entity with bundles #3129

Closed
tahirm opened this issue Jan 24, 2017 · 0 comments

Comments

@tahirm
Copy link

tahirm commented 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

  • Drupal version: 8.2.5.
  • Console version: 1.0.0-rc14
  • Console Launcher version (using drupal-composer project).

Steps to reproduce

  • 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.

@tahirm 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant