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

Custom CRUD actions broken in 4.20.3 #6652

Open
simoheinonen opened this issue Dec 16, 2024 · 5 comments
Open

Custom CRUD actions broken in 4.20.3 #6652

simoheinonen opened this issue Dec 16, 2024 · 5 comments

Comments

@simoheinonen
Copy link
Contributor

Describe the bug

TypeError:
EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext::getEntity(): Return value must be of type EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto, null returned

  at vendor/easycorp/easyadmin-bundle/src/Context/AdminContext.php:90
  at EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext->getEntity()
     (src/Controller/Admin/FooBarCrudController.php:159)
  at App\Controller\Admin\FooBarCrudController->customAction(object(AdminContext))
     (vendor/symfony/http-kernel/HttpKernel.php:183)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:76)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:182)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php:35)
  at Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner->run()
     (vendor/autoload_runtime.php:29)
  at require_once('/Users/simo/Projects/foo/bar/vendor/autoload_runtime.php')
     (public/index.php:5)                

To Reproduce

Use version 4.20.3

public function customAction(AdminContext $context): RedirectResponse
{
    $context->getEntity()->getInstance(); // fails because entity is NULL
}

Works fine with 4.20.2

@simoheinonen
Copy link
Contributor Author

Not sure if related to #6646

@MrJuliuss
Copy link

Hi, i had the same issue when i tried to migrate to new pretty urls yesterday, and fix it with AdminAction attributes

https://symfony.com/bundles/EasyAdminBundle/current/actions.html#adding-custom-actions

#[AdminAction(routePath: '/invoice', routeName: 'view_invoice', methods: ['GET', 'POST'])]
public function renderInvoice(AdminContext $context)
{
    // ...
}

@duha99
Copy link

duha99 commented Dec 17, 2024

Hi, i had the same issue when i tried to migrate to new pretty urls yesterday, and fix it with AdminAction attributes

https://symfony.com/bundles/EasyAdminBundle/current/actions.html#adding-custom-actions


#[AdminAction(routePath: '/invoice', routeName: 'view_invoice', methods: ['GET', 'POST'])]

public function renderInvoice(AdminContext $context)

{

    // ...

}

Same solution worked for me.
When using Pretty URLs AdminAction Routes seems to be required.

It's similar to the requirements in BatchActions in this Issue #6532

@simoheinonen
Copy link
Contributor Author

Thanks for the workaround!

Would be good to have a proper fix for this though

@ben29
Copy link

ben29 commented Dec 18, 2024

same thing here also.
it's something with the new bug fix.

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

4 participants