EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given
EasyAdmin Version: >=4.21.0
Describe the bug
ErrorException: An exception has been thrown during the rendering of a template ("EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given, called in /home/runner/work/user/user/vendor/twig/twig/src/Extension/CoreExtension.php on line 1871").
To Reproduce
public function testIndexPage2(): void
{
SampleFactory::createMany(5);
// retrieve the test user
$testUser = UserFactory::createOne();
// simulate $testUser being logged in
$this->client->loginUser($testUser->_real());
// this examples doesn't use security; in your application you may
// need to ensure that the user is logged before the test
$this->client->request(Request::METHOD_GET, $this->generateIndexUrl());
static::assertResponseIsSuccessful();
}
(OPTIONAL) Additional context Pretty URLs are on, I have a second identical test just pointing to a different entity/crud where this does not fail, and unlike #6715 this stops working with 4.21.0, though it seems very similar.
| Version | Success |
|---|---|
| 4.20.8 | ✅ |
| 4.21.0 | ❌ |
| 4.21.1 | ❌ |
| 4.22.0 | ❌ |
It might have been fixed by #6737.
I've upgraded and it's not fixed when i'm on a custom action WITH a search query in the
i.e
http://admin.localhost:8787/?crudAction=myCustomAction&crudControllerFqcn=App%5CController%5CAdmin%5CSomethingCrudController&entityId=365&query=x
This issue is still valid, same here.
I got excited for a bit because I thought it had been resolved for me as well, but realized late last night that the tests were still failing.
I have the same problem. It can be reproduced if you follow the instructions
https://symfony.com/bundles/EasyAdminBundle/current/actions.html#batch-actions
After clicking on the batch action button, symfony throws the corresponding error.
@javiereguiluz yes having same problem with batch action button (with pretty urls enabled):
Uncaught PHP Exception TypeError: "EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given, called in /home/bas/app_1e8a7d42-ba90-4f14-bc0b-0ae8202e27ba/vendor/easycorp/easyadmin-bundle/src/ArgumentResolver/BatchActionDtoResolver.php on line 66" at AdminUrlGenerator.php line 42
Hi all! php 8.2, EA v4.24.3 with pretty admin URLs
- According Adding Custom Actions):
-
add custom action:
public function configureActions(Actions $actions): Actions { // this action executes the 'renderInvoice()' method of the current CRUD controller $viewInvoice = Action::new('viewInvoice', 'Invoice', 'fa fa-file-invoice') ->linkToCrudAction('renderInvoice'); ... }
-
add CRUD-function
public function renderInvoice(AdminContext $context) { dd($context); $order = $context->getEntity()->getInstance(); ... }
-
as a result:
[EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext] ... -entityDto: null
- For Batch Actions
I'm getting an error:
EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given, called in /home/er/php/project1/vendor/easycorp/easyadmin-bundle/src/ArgumentResolver/BatchActionDtoResolver.php on line 66
- When linkToRoute() is used for a custom action:
$actions ->add(Crud::PAGE_INDEX, Action::new('testReport', 'Test') ->linkToRoute('app_admin_test_report', static fn (Bank $bank) => [ 'id' => $bank->getId(), ])
It's okay.
- And if use linkToRoute() for batch action
$actions ->addBatchAction(Action::new('getBanksReport', 'label.report') ->linkToRoute('app_admin_report_banks');
then in Symfony controller:
[Route('/admin/report/banks', name: 'app_admin_report_banks', methods: ['POST'])] public function banks(Request $request): Response { $batchActionEntityIds = $request->request->all( \EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA::BATCH_ACTION_ENTITY_IDS ); // ids array ... }
It's okay.
Custom actions must now use the attribute #[AdminAction] to make them work.
Custom actions can define the #[AdminAction]
Which is "must define" in the current case.
I'll transform my PR to cover both cases.
I fixed it somehow by removing
easyadmin:
resource: .
type: easyadmin.routes
from easyadmin.yaml that was added when updating the flex recipe.