EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given

Open richard4339 opened this issue 1 year ago • 10 comments

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

richard4339 avatar Jan 15 '25 16:01 richard4339

It might have been fixed by #6737.

javiereguiluz avatar Jan 18 '25 18:01 javiereguiluz

I've upgraded and it's not fixed when i'm on a custom action WITH a search query in the

allan-simon avatar Jan 20 '25 13:01 allan-simon

i.e

http://admin.localhost:8787/?crudAction=myCustomAction&crudControllerFqcn=App%5CController%5CAdmin%5CSomethingCrudController&entityId=365&query=x

allan-simon avatar Jan 20 '25 14:01 allan-simon

This issue is still valid, same here.

dfridrich avatar Jan 28 '25 11:01 dfridrich

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.

richard4339 avatar Jan 28 '25 13:01 richard4339

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.

dark-cms avatar Feb 10 '25 09:02 dark-cms

@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

Huluti avatar Feb 12 '25 13:02 Huluti

Hi all! php 8.2, EA v4.24.3 with pretty admin URLs

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

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

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

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

devdepart avatar Feb 14 '25 11:02 devdepart

Custom actions must now use the attribute #[AdminAction] to make them work.

The documentation says

Custom actions can define the #[AdminAction]

Which is "must define" in the current case.

I'll transform my PR to cover both cases.

thomas-l avatar Apr 30 '25 09:04 thomas-l

I fixed it somehow by removing

easyadmin:
    resource: .
    type: easyadmin.routes

from easyadmin.yaml that was added when updating the flex recipe.

conradfr avatar Jun 11 '25 13:06 conradfr