Search code examples
routesfosrestbundlesulu

Sulu: custom entity type - FOS rest api routes are missing


I followed Sulu documentations for adding custom entity types to Sulu and at point:

https://docs.sulu.io/en/2.2/book/extend-admin.html#configure-resources

when calling : bin/adminconsole debug:router | grep event

I should get all kinds of routes for complete rest api.

However, when I call it like that I get only one route listed:

app.get_events                                  GET      ANY      ANY    /admin/api/events.{_format} 

Documentation there says "If you have already created other actions as well,..", but again admin EventController class has that annotation:

/**
 * @RouteResource("event")
 */

.. so I'm not sure should I manually create a method for each rest action (GET, PUT, DELETE...) or they should be created automatically? If they should be created automatically then why I don't see those routes?


Solution

  • None of the operations are generated automatically. If you followed the documentation about extending the admin, you probably only have implemented the cgetAction() method, right? Therefore only the app.get_events route has been registered. As soon as you implement e.g. a postAction(), a app.post_event route will be registered for you. But you always have to implement the crud functionality for your custom entity by yourself, Sulu can't do that for you, because it's completely up to you, how your custom entity is stored (could be also stored as a file in your filesystem or as a document in elasticsearch)

    Normally it's quite helpful to have a look at Sulu's internal bundles (the SuluTagBundle is quite an easy one) or other resources on github (e.g. Sulu Workshop and Sulu Demo) to see how such things are working.