EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.04k stars 1.02k forks source link

Action with only url can't be updated properly #6359

Open Clement-B opened 2 months ago

Clement-B commented 2 months ago

Bug description

An action created with only a url link cannot be updated with function $actions->update.

Steps to reproduce

  1. 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 ?

Clement-B commented 2 months ago

Seems that a PR is already waiting review : #6265