<?php
declare(strict_types=1);
namespace Bluue\TicketsBundle\EventSubscriber;
use App\Event\MassManagementListButtonsEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class ConfigureListButtonsSubscriber implements EventSubscriberInterface
{
/**
* @var RouterInterface
*/
private RouterInterface $router;
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @param RouterInterface $router
* @param TranslatorInterface $tr
*/
public function __construct(RouterInterface $router, TranslatorInterface $tr)
{
$this->router = $router;
$this->tr = $tr;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
MassManagementListButtonsEvent::NAME => 'onLoad'
];
}
/**
* @param MassManagementListButtonsEvent $event
* @return void
*/
public function onLoad(MassManagementListButtonsEvent $event): void
{
if (str_starts_with($event->getListName(), '_tickets_bundle__ticket_list_')) {
$buttons = $event->getButtons();
$massSpamBtn = '<a href="' . $this->router->generate(
'tickets_bundle__ticket_mass_spam'
) . '" ';
$massSpamBtn .= 'class="btn btn-sm btn-primary mx-2">';
$massSpamBtn .= $this->tr->trans('Spam', [], 'TicketsBundle') . '</a>';
$massChangeStatusBtn = '<a href="' . $this->router->generate(
'tickets_bundle__ticket_mass_change_status'
) . '" class="btn btn-sm btn-primary mx-2 bluue-modal-button" ' .
'bluue-modal-label="' . $this->tr->trans('Change state', [], 'TicketsBundle') . '">';
$massChangeStatusBtn .= $this->tr->trans('Change state', [], 'TicketsBundle') . '</a>';
$buttons[] = [$massSpamBtn];
$buttons[] = [$massChangeStatusBtn];
$event->setButtons($buttons);
}
}
}