Adding a custom form inside the show template of a Sonata Admin Entity
The _sonata_admin
(route) attribute is used by SonataAdminBundle
to get the required admin instance ($this->admin
) and be able to configure/process your requests:
After to add the right route definition:
protected function configureRoutes(RouteCollection $collection){ $collection->add('approve_order', $this->getRouterIdParameter().'/approve');}
You need to add also the _sonata_admin
code to generate the right request to approveOrderAction()
:
{{ render(controller('QiBssFrontendBundle:PmodOrderCRUD:approveOrder', { 'id': object.id, '_sonata_admin': '...' })) }}
Let's make a simple example:
You have an Order
entity and its admin class: OrderAdmin
into PurchaseBundle
, so this is the Sonata's service definition for OrderAdmin
class (Yaml):
services: purchase_bundle.admin.order_admin: class: PurchaseBundle\Admin\OrderAdmin arguments: - ~ - PurchaseBundle\Entity\Order - ~ tags: - { name: 'sonata.admin', manager_type: orm }
Now, based on your own approveOrderAction()
, you can render this action in the follows way:
{{ render(controller('PurchaseBundle:OrderAdmin:approveOrder', { 'id': object.id, '_sonata_admin': 'purchase_bundle.admin.order_admin' })) }}
Just you have to add the admin code: 'purchase_bundle.admin.order_admin'
and it should work!