Skip to content

global batch action giving crudControllerFqcn null error #7320

@shambhu384

Description

@shambhu384

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());
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions