EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Unable to customize DELETE action URL

Open nevez opened this issue 5 months ago • 2 comments

In the CrudController configureActions() method, if I write this:

$actions->update(Crud::PAGE_INDEX, Action::DELETE, function (Action $action) {
    return $action
        ->linkToUrl(fn ($entity) => ...anything here...)
    ;
})

The updated url is correctly displayed on the "Delete" action link, but if you click the button, the delete form POSTs to a fixed url, specified in the "formaction" attribute of the action link.

The problem probably originates here, in ActionFactory.php method processAction():

        if (Action::DELETE === $actionDto->getName()) {
            $actionDto->addHtmlAttributes([
                'formaction' => $this->adminUrlGenerator->setController($adminContext->getCrud()->getControllerFqcn())->setAction(Action::DELETE)->setEntityId($entityDto->getPrimaryKeyValue())->generateUrl(),
                'data-bs-toggle' => 'modal',
                'data-bs-target' => '#modal-delete',
            ]);
        }

Maybe the "formaction" attribute should take the action url?

nevez avatar Sep 03 '25 16:09 nevez

@nevez thanks for reporting this error. I think you are right about the cause of the problem. Can you please submit a pull request against 4.x branch to fix it? Thanks!

javiereguiluz avatar Sep 14 '25 18:09 javiereguiluz

i think the addCssClass method is not working either

i.e. .addCssClass('btn btn-primary')

pfpro avatar Oct 11 '25 15:10 pfpro