linkToCrudAction not working
Describe the bug
linkToCrudAction does not actually link the button to the method supplied in arguments.
To Reproduce
// Controller/Admin/CRUD/ModelCrudController.php
class ModelCrudController {
// ...
public function configureActions(Actions $actions): Actions
{
$myNewAction= Action::new(
'my_new_act',
t('action.create_and_add_another', domain: 'EasyAdminBundle')
)->linkToCrudAction('createNewModel');
return $actions
->add(Crud::PAGE_NEW, $myNewAction);
}
// ...
public function createNewModel(AdminContext $context) {
dump($context->getRequest()->request->all());die;
}
// ...
createNewModel is never called when clicking on the corresponding button.
(OPTIONAL) Additional context same problem when updating an existing action, ie
return $actions->update(Crud::PAGE_NEW, Action::SAVE_AND_ADD_ANOTHER, function (Action $action) {
return $action->linkToCrudAction('createNewModel');
});
Hi,
Because you need to create an action "createNewModel".
linkToCrudAction need an action name, not the method.
Hi,
Because you need to create an action "createNewModel".
linkToCrudAction need an action name, not the method.
in the documentation the method name is used. Otherwise, how would I define what function is called when the button is clicked ?
I do this and it's working:
public const NEW_ACTION = 'myNewAction';
In configureActions:
Action::new(self::NEW_ACTION , 'Label')
->linkToCrudAction(self::NEW_ACTION)
public function myNewAction(...
In you case, i think you can rename my_new_act -> createNewModel
in the documentation the method name is used.
I'm agree with you. The doc says:
// this action executes the 'renderInvoice()' method of the current CRUD controller
$viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice')
->linkToCrudAction('renderInvoice');
But the definition in Action.php is:
public function linkToCrudAction(string $crudActionName): self
I think the comment should be:
// this action executes 'viewInvoice()' method of the current CRUD controller, but redirect to 'renderInvoice' action on click (and execute 'renderInvoice()' method)