EasyAdminBundle
EasyAdminBundle copied to clipboard
Action with only url can't be updated properly
Bug description
An action created with only a url link cannot be updated with function $actions->update
.
Steps to reproduce
- Add to controller in
configureActions
function following code:
$actions->add(Crud::PAGE_INDEX,
Action::new('testAction')
->linkToUrl('/test')
);
$actions->update(Crud::PAGE_INDEX, 'testAction', fn (Action $action) => $action->setLabel('Test button updated'));
Observed result
We got following error:
Actions must link to either a route, a CRUD action, or a URL. Set the "linkToCrudAction()", "linkToRoute()", or "linkToUrl()" method for the "testAction" action.
Expected result
We should not have error and see the new action in index page.
Analyze and possible fix
When updating an action, we recreate them based on dto information thanks to function getAsConfigObject
in class ActionDto.php
and then get the dto again based on a the new object created. During this process, url value is lost and we then got an error message.
We could improve function getAsConfigObject
in class ActionDto.php
by including url in config object with just a few line to add:
if (null !== $this->url) {
$action->linkToUrl($this->url);
}
I tested it briefly and it works but maybe it was intended to not take care or url value ?