global batch action giving crudControllerFqcn null error

Open
#7,320 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
php, symfony
Domain
backend

Research direction

Start with ArgumentResolver/BatchActionDtoResolver.php at line 65 and the AdminUrlGenerator::setController() call, then reproduce the global batch action using the ListingCrudController example. Trace why the batch action has no CRUD controller and add or update a regression test so the action completes without passing null.

Written by the indexing model from the issue text.

Description

bug

Describe the bug
EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setController(): Argument #1 ($crudControllerFqcn) must be of type string, null given, called in /home/shivansh/Workspace/brokertruf/vendor/easycorp/easyadmin-bundle/src/ArgumentResolver/BatchActionDtoResolver.php on line 65

To Reproduce
try to create global batch action

<?php

namespace App\Controller\Admin;

use App\Entity\Listing;
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminAction;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;

class ListingCrudController extends AbstractCrudController
{
    public function __construct(
        private EntityManagerInterface $entityManager
    ) {}

    public static function getEntityFqcn(): string
    {
        return Listing::class;
    }

    public function configureActions(Actions $actions): Actions
    {
        $batchUpdate = Action::new('batchUpdate', 'Update Age')
            ->linkToCrudAction('batchUpdate')
            ->addCssClass('btn btn-primary')
            ->setIcon('fa fa-clock');

        return $actions
            ->addBatchAction($batchUpdate);
    }

    public function batchUpdate(BatchActionDto $batchActionDto): Response
    {
        $entityIds = $batchActionDto->getEntityIds();
        
        try {
            $qb = $this->entityManager->createQueryBuilder();
            $qb->update($batchActionDto->getEntityFqcn(), 'e')
                ->set('e.ageOfListing', ':now')
                ->where($qb->expr()->in('e.id', ':ids'))
                ->setParameter('now', new \DateTimeImmutable('now'))
                ->setParameter('ids', $entityIds)
                ->getQuery()
                ->execute();
            
            $this->addFlash('success', sprintf('%d listing(s) updated.', count($entityIds)));
        } catch (\Exception $e) {
            $this->addFlash('error', 'Update failed.');
        }
        
        return $this->redirect($batchActionDto->getReferrerUrl());
    }
}
Dominant language
PHP
Stars
4.3k
Forks
1.1k
Avg merge
2d 9h
Merged PRs (30d)
52

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EasyCorp/EasyAdminBundle

All issues in EasyCorp/EasyAdminBundle

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.