0

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?

MilanG
  • 6,994
  • 2
  • 35
  • 64

1 Answers1

1

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.

Luca Rath-Heel
  • 210
  • 1
  • 8
  • Thanks. Added them manually and they are shown now. Only problem is with put action. If I define method like "putAction(Request $request, int $id): Response" as in your example id parameter is missing in route. It appears if I switch parameter orders and place $id first. Is it the proper way? – MilanG May 11 '21 at 06:41
  • Unfortunately I cannot reproduce that behaviour. Placing the `$id` parameter in the second place works totally fine for me. You could try to clear the cache using `rm -rf var/cache/*`, sometime this helps – Luca Rath-Heel May 11 '21 at 08:32
  • Yes, this step is sorely missing from that Sulu tutorial and has caused a lot of head scratching for us as well. – YetiCGN Aug 25 '21 at 10:52