Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding custom crud action on the NEW page generates an invalid URL to it #6474

Open
speller opened this issue Oct 14, 2024 · 1 comment
Open

Comments

@speller
Copy link

speller commented Oct 14, 2024

Describe the bug
When I add a custom action to the NEW page, I'm getting the entity with "id = 0" does not exist in the database error when trying to access it.

To Reproduce

    public function configureActions(Actions $actions): Actions
    {
        return parent::configureActions($actions)
            ->add(
                Crud::PAGE_NEW,
                Action::new('foo', 'Foo')->linkToCrudAction('foo')
            )
        ;
    }

(OPTIONAL) Additional context

The "App\Entity\Foo" entity with "id = 0" does not exist in the database. The entity may have been deleted by mistake or by a "cascade={"remove"}" operation executed by Doctrine.

Stack:

in vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php (line 149)
in vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php -> getEntityInstance (line 111)
in vendor/easycorp/easyadmin-bundle/src/Factory/EntityFactory.php -> doCreate (line 70)
in vendor/easycorp/easyadmin-bundle/src/Factory/AdminContextFactory.php -> create (line 244)
in vendor/easycorp/easyadmin-bundle/src/Factory/AdminContextFactory.php -> getEntityDto (line 62)
in vendor/easycorp/easyadmin-bundle/src/EventListener/AdminRouterSubscriber.php -> create (line 78)
in vendor/symfony/event-dispatcher/Debug/WrappedListener.php -> onKernelRequest (line 116)
in vendor/symfony/event-dispatcher/EventDispatcher.php -> __invoke (line 206)
in vendor/symfony/event-dispatcher/EventDispatcher.php -> callListeners (line 56)
in vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php -> dispatch (line 127)
in vendor/symfony/http-kernel/HttpKernel.php -> dispatch (line 154)
in vendor/symfony/http-kernel/HttpKernel.php -> handleRaw (line 76)

The URL that is generated for the action: http://localhost:7000/dashboard?crudAction=foo&crudControllerFqcn=App%5CController%5CFooCOntroller&entityId=0

@damien-louis
Copy link

linkToCrudAction seems to be related to action on a specific row of your entity.
You have to disable new button and create another new button to call your custom controller (with route named backoffice_user_create for example):

    public function configureActions(Actions $actions): Actions
    {

        $customNewAction = Action::new('customNew', 'Add New')
            ->linkToRoute('backoffice_user_create')->addCssClass('btn btn-primary')->createAsGlobalAction()
        ;

        return $actions
            ->add(Crud::PAGE_INDEX, $customNewAction)
           ->disable(Action::NEW)
        ;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants