vendor/bluue/sales-bundle/src/EventSubscriber/ConfigureListButtonsSubscriber.php line 54

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bluue\SalesBundle\EventSubscriber;
  4. use App\Event\MassManagementListButtonsEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\Routing\RouterInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. class ConfigureListButtonsSubscriber implements EventSubscriberInterface
  10. {
  11.     /**
  12.      * @var RouterInterface
  13.      */
  14.     private RouterInterface $router;
  15.     /**
  16.      * @var TranslatorInterface
  17.      */
  18.     private TranslatorInterface $tr;
  19.     /**
  20.      * @var Security
  21.      */
  22.     private Security $security;
  23.     public function __construct(
  24.         RouterInterface $router,
  25.         TranslatorInterface $tr,
  26.         Security $security
  27.     ) {
  28.         $this->router $router;
  29.         $this->tr $tr;
  30.         $this->security $security;
  31.     }
  32.     /**
  33.      * @return string[]
  34.      */
  35.     public static function getSubscribedEvents(): array
  36.     {
  37.         return [
  38.             MassManagementListButtonsEvent::NAME => 'onLoad',
  39.         ];
  40.     }
  41.     /**
  42.      * @param MassManagementListButtonsEvent $event
  43.      * @return void
  44.      */
  45.     public function onLoad(MassManagementListButtonsEvent $event): void
  46.     {
  47.         $buttons $event->getButtons();
  48.         $types = ['order''invoice''delivery_note''credit_note''quotation'];
  49.         foreach ($types as $type) {
  50.             if (str_starts_with($event->getListName(), '_sales_bundle__' $type '_list_')) {
  51.                 $printBtn '<a target="_blank" href="';
  52.                 $printBtn .= $this->router->generate(
  53.                     'sales_bundle__mass_generation_pdf',
  54.                     ['type' => $type]
  55.                 ) . '" ';
  56.                 $printBtn .= 'class="btn btn-sm btn-primary mx-2">';
  57.                 $printBtn .= $this->tr->trans('Print', [], 'SalesBundle') . '</a>';
  58.                 $printBtn .= '<a href="' $this->router->generate(
  59.                     'sales_bundle__document_export_all',
  60.                     ['document' => $type]
  61.                 ) . '"';
  62.                 $printBtn .= ' class="btn btn-sm btn-primary bluue-modal-button" bluue-modal-label="';
  63.                 $printBtn .= $this->tr->trans('Send by mail', [], 'SalesBundle') . '">';
  64.                 $printBtn .= $this->tr->trans('Send by mail', [], 'SalesBundle') . '</a>';
  65.                 if ($this->security->isGranted('ROLE__SALES__ADMIN') && $type == 'delivery_note') {
  66.                     $printBtn .= '<form action="' $this->router->generate(
  67.                         'sales_bundle__invoice_multiple_delivery_notes',
  68.                         ['document' => $type]
  69.                     ) . '" method="POST" id="invoiceDeliveryNotes" class="mx-2">';
  70.                     $printBtn .= '<button type="submit" class="btn btn-primary btn-sm">';
  71.                     $printBtn .= $this->tr->trans('Invoice delivery notes', [], 'SalesBundle');
  72.                     $printBtn .= '</button></form>';
  73.                 }
  74.                 $buttons[] = [$printBtn];
  75.             }
  76.         }
  77.         $event->setButtons($buttons);
  78.     }
  79. }