<?php
/**
* @author Thomas HERISSON (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\ShipmentsPictureBundle\EventSubscriber;
use Bluue\ShipmentsBundle\Event\ConfigurationBurstButtonsEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureBurstButtonsSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @param TranslatorInterface $tr
* @param Security $security
*/
public function __construct(
TranslatorInterface $tr,
Security $security
) {
$this->tr = $tr;
$this->security = $security;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
ConfigurationBurstButtonsEvent::NAME => 'onLoad'
];
}
/**
* @param ConfigurationBurstButtonsEvent $event
* @return void
*/
public function onLoad(ConfigurationBurstButtonsEvent $event): void
{
if (!$this->security->isGranted('ROLE__SHIPMENTS_PICTURE__SMALL_ADMIN')) {
return;
}
$buttons = $event->getButtons();
$buttons[] = [
'path' => 'shipments_picture_bundle__modal_picture',
'name' => $this->tr->trans('Send photo by email', [], 'ShipmentsPictureBundle')
];
$buttons[] = [
'path' => 'shipments_picture_bundle__modal_picture_list',
'name' => $this->tr->trans('Show pictures', [], 'ShipmentsPictureBundle')
];
$event->setButtons($buttons);
}
}