EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Custom BatchAction uses old URL with TypeError instead of Pretty URL

Open duha99 opened this issue 1 year ago • 3 comments

Describe the bug When using Pretty URLs in 4.14.5 and adding a custom BatchAction, the Button gets populated with the old URL style. When calling this URL a TypeError is thrown: EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given, called in C:\Users\Chris\PhpstormProjects\beratungssoftware\vendor\easycorp\easyadmin-bundle\src\ArgumentResolver\BatchActionDtoResolver.php on line 67

To Reproduce

  1. Add any Custom BatchAction to a Crud Controller
  2. Call the BatchAction

Additional context It seems like the custom BatchAction handling just slipped through, when adding the Pretty URLs and only the URL handling needs a small change.

grafik

duha99 avatar Nov 12 '24 11:11 duha99

You can fix this error by adding the #[AdminAction] attribute to your batch action method. e.g. something like this (the methods: POST is important here, as batch actions are submitted via POST):

#[AdminAction(routePath: '/sepa-xml-export', routeName: 'admin_payment_order_sepa_xml_export', methods: ['POST'])]
public function sepaXMLExport(BatchActionDto $batchActionDto): Response
{
...

I think it would be fine, if you would need to define a proper admin action path properly (this way it is also explicitly marked that this method is something like a route). But then a proper error message should be shown, and not the current (rather cryptic one).

jbtronics avatar Dec 01 '24 01:12 jbtronics

Thanks a lot @jbtronics for solving my Problem.

@javiereguiluz it would be fantastic to add that to the Documentation

duha99 avatar Dec 02 '24 11:12 duha99

Adding an AdminRoute attribute, as recommended in the doc, worked for me on v4.27.4.

NicolasGraph avatar Nov 28 '25 08:11 NicolasGraph