vendor/bluue/projects-bundle/src/EventSubscriber/ConfigureListButtonsSubscriber.php line 70

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\ProjectsBundle\EventSubscriber;
  4. use App\Event\MassManagementListButtonsEvent;
  5. use App\Services\Context;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\Routing\RouterInterface;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
  10. use Symfony\Component\Security\Core\Security;
  11. class ConfigureListButtonsSubscriber implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var RouterInterface
  15.      */
  16.     private RouterInterface $router;
  17.     /**
  18.      * @var TranslatorInterface
  19.      */
  20.     private TranslatorInterface $tr;
  21.     /**
  22.      * @var CsrfTokenManagerInterface
  23.      */
  24.     private CsrfTokenManagerInterface $csrfToken;
  25.     /**
  26.      * @var Security
  27.      */
  28.     private Security $security;
  29.     /**
  30.      * @var Context
  31.      */
  32.     private Context $contextService;
  33.     public function __construct(
  34.         RouterInterface $router,
  35.         TranslatorInterface $tr,
  36.         CsrfTokenManagerInterface $csrfToken,
  37.         Context $contextService,
  38.         Security $security
  39.     ) {
  40.         $this->router $router;
  41.         $this->tr $tr;
  42.         $this->csrfToken $csrfToken;
  43.         $this->contextService $contextService;
  44.         $this->security $security;
  45.     }
  46.     /**
  47.      * @return string[]
  48.      */
  49.     public static function getSubscribedEvents(): array
  50.     {
  51.         return [
  52.             MassManagementListButtonsEvent::NAME => 'onLoad',
  53.         ];
  54.     }
  55.     /**
  56.      * @param MassManagementListButtonsEvent $event
  57.      * @return void
  58.      */
  59.     public function onLoad(MassManagementListButtonsEvent $event): void
  60.     {
  61.         $buttons $event->getButtons();
  62.         $context $this->contextService->getActualOrDefault();
  63.         if (
  64.             (
  65.                 str_starts_with($event->getListName(), '_projects_bundle__task_list_') ||
  66.                 str_starts_with($event->getListName(), '_projects_bundle__customer_task_list_')
  67.             )
  68.              &&
  69.             $this->security->isGranted('ROLE__PROJECTS__SUPER_ADMIN')
  70.         ) {
  71.             $param = [];
  72.             if (str_starts_with($event->getListName(), '_projects_bundle__customer_task_list_')) {
  73.                 $listNameExplode explode('_'$event->getListName());
  74.                 $customerId $listNameExplode[array_key_last($listNameExplode)];
  75.                 $param['customerId'] = $customerId;
  76.             }
  77.             $deleteBtn '<form action="';
  78.             $deleteBtn .= $this->router->generate('projects_bundle__task_mass_delete'$param);
  79.             $deleteBtn .= '" method="post">';
  80.             $deleteBtn .= '<input type="hidden" name="_token" value="';
  81.             $deleteBtn .= $this->csrfToken->getToken('mass-delete' $context->getId());
  82.             $deleteBtn .= '"><button type="submit" class="btn btn-sm btn-danger" data-submit-alert="';
  83.             $deleteBtn .= $this->tr->trans(
  84.                 'Really want to remove tasks selected?',
  85.                 [],
  86.                 'ProjectsBundle'
  87.             ) . '">';
  88.             $deleteBtn .= $this->tr->trans(
  89.                 'Remove tasks selected',
  90.                 [],
  91.                 'ProjectsBundle'
  92.             ) . '</button></form>';
  93.             $buttons[] = [$deleteBtn];
  94.         }
  95.         $event->setButtons($buttons);
  96.     }
  97. }