EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

add possibility to use route parameters on crud actions

Open CodinKitchen opened this issue 3 years ago • 2 comments

Short description of what this feature will allow to do: This feature will allow to pass query parameters to crud actions. It can be useful to be able to reuse the same action with little variations based on parameters.

Example of how to use this feature Usage will be similar to linkToRoute, passing query parameters as second method param.

$viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
    ->linkToCrudAction('renderInvoice', ['type' => 'pdf']); 

See PR #5144

CodinKitchen avatar Apr 08 '22 10:04 CodinKitchen

Hello,

You can do it this way:

// inject EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator in your CrudController

$url = $this
    ->adminUrlGenerator
    ->unsetAll()
    ->setController(self::class)
    ->setAction('renderInvoice')
    ->set('type', 'pdf')
    ->generateUrl();

$viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
    ->linkToUrl($url); 

Regards

fabienlem avatar Apr 10 '22 16:04 fabienlem

Thx @fabienlem I did not thought about doing it this way :) Definitely going to do this for now.

Still I think it could make things more understandable if we could add parameters when using linkToCrud. Oterwise it sounds a bit like a trick.

CodinKitchen avatar Apr 11 '22 22:04 CodinKitchen