global batch action giving crudControllerFqcn null error

Aperta
#7,320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
php, symfony
Ambito
backend

Direzione di ricerca

Inizia da ArgumentResolver/BatchActionDtoResolver.php alla riga 65 e dalla chiamata a AdminUrlGenerator::setController(), quindi riproduci l’azione batch globale usando l’esempio di ListingCrudController. Traccia il motivo per cui l’azione batch non ha un controller CRUD e aggiungi o aggiorna un test di regressione in modo che l’azione venga completata senza passare null.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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());
    }
}
Lingua principale
PHP
Stelle
4.3k
Fork
1.1k
Merge medio
2g 9h
PR unite (30g)
52

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di EasyCorp/EasyAdminBundle

Tutte le issue di EasyCorp/EasyAdminBundle

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.