Skip to content

Commit

Permalink
refactor(admin): Remove batch actions
Browse files Browse the repository at this point in the history
Remove these actions temporarily. We don't use it often.

Related: EasyCorp/EasyAdminBundle#6532
  • Loading branch information
pan93412 committed Nov 27, 2024
1 parent 0a78b48 commit c4a150c
Showing 1 changed file with 0 additions and 59 deletions.
59 changes: 0 additions & 59 deletions src/Controller/Admin/FeedbackCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
namespace App\Controller\Admin;

use App\Entity\Feedback;
use App\Entity\FeedbackStatus;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\BatchActionDto;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
Expand All @@ -21,18 +18,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;

use function Symfony\Component\Translation\t;

class FeedbackCrudController extends AbstractCrudController
{
public function __construct(private readonly AdminUrlGenerator $adminUrlGenerator)
{
}

public static function getEntityFqcn(): string
{
return Feedback::class;
Expand Down Expand Up @@ -67,57 +55,10 @@ public function configureFilters(Filters $filters): Filters
public function configureActions(Actions $actions): Actions
{
$actions->add(Crud::PAGE_INDEX, Action::DETAIL);
$actions->addBatchAction(
Action::new('mark_resolved', icon: 'fa fa-check')
->linkToUrl(
$this
->adminUrlGenerator
->unsetAll()
->setController(self::class)
->setAction('markStatus')
->set('status', FeedbackStatus::Resolved->value)
->generateUrl()
)
);
$actions->addBatchAction(
Action::new('mark_closed', icon: 'fa fa-xmark')
->linkToUrl(
$this
->adminUrlGenerator
->unsetAll()
->setController(self::class)
->setAction('markStatus')
->set('status', FeedbackStatus::Closed->value)
->generateUrl()
)
);

return $actions;
}

public function markStatus(
BatchActionDto $batchActionDto,
EntityManagerInterface $entityManager,
#[MapQueryParameter] FeedbackStatus $status,
): Response {
$repository = $entityManager->getRepository(Feedback::class);

foreach ($batchActionDto->getEntityIds() as $entityId) {
$feedback = $repository->find($entityId);
if (null === $feedback) {
continue;
}

$feedback->setStatus($status);
$entityManager->persist($feedback);
}

$entityManager->flush();
$this->addFlash('success', t('feedback.marked', ['%status%' => $status]));

return $this->redirect($batchActionDto->getReferrerUrl());
}

public function configureCrud(Crud $crud): Crud
{
return $crud->setDefaultSort(['createdAt' => 'DESC']);
Expand Down

0 comments on commit c4a150c

Please sign in to comment.