<?php
declare(strict_types=1);
namespace Bluue\ShipmentsBundle\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(), '_shipments_bundle__order_list_')) {
$buttons = $event->getButtons();
$btnOneBurstByOrder = '<a href="' .
$this->router->generate('shipments_bundle__burst_new_burst_from_orders', ['one_burst' => 1]) .
'" class="btn btn-primary btn-sm bluue-modal-button mx-1" bluue-modal-label="' .
$this->tr->trans('Create burst for each order', [], 'ShipmentsBundle') . '">' .
$this->tr->trans('Create burst for each order', [], 'ShipmentsBundle') . '</a>';
$btnOrdersToBurst = '<a href="' . $this->router->generate('shipments_bundle__burst_new_burst_from_orders') .
'" class="btn btn-primary btn-sm bluue-modal-button mx-1" bluue-modal-label="' .
$this->tr->trans('Create burst from orders', [], 'ShipmentsBundle') . '">' .
$this->tr->trans('Create burst from orders', [], 'ShipmentsBundle') . '</a>';
$buttons[] = [$btnOneBurstByOrder];
$buttons[] = [$btnOrdersToBurst];
$event->setButtons($buttons);
}
}
}