<?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\AdelyaBundle\EventSubscriber;
use App\Event\MenuConfigurationPageEvent;
use Bluue\CashRegisterBundle\Event\MenuConfigurationPageCashRegisterEvent;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigurationBundleSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var RequestStack
*/
protected RequestStack $requestStack;
/**
* @param RequestStack $requestStack
* @param TranslatorInterface $tr
*/
public function __construct(
RequestStack $requestStack,
TranslatorInterface $tr
) {
$this->requestStack = $requestStack;
$this->tr = $tr;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
MenuConfigurationPageEvent::NAME => 'configurationMenu',
MenuConfigurationPageCashRegisterEvent::NAME => 'cashRegisterMenu',
];
}
/**
* @param MenuConfigurationPageEvent $event
* @return void
*/
public function configurationMenu(MenuConfigurationPageEvent $event): void
{
$pages = $event->getPages();
$keyCashRegisterMenu = array_search('adelya_bundle__configuration_settings', array_column($pages, 'id'));
if (is_numeric($keyCashRegisterMenu)) {
$pages[$keyCashRegisterMenu]['subpages'][] = ['id' => 'adelya_bundle__configuration_settings'];
$event->setPages($pages);
}
}
/**
* @param MenuConfigurationPageCashRegisterEvent $event
* @return void
*/
public function cashRegisterMenu(MenuConfigurationPageCashRegisterEvent $event): void
{
$pages = $event->getPages();
$pages[] = [
'id' => 'adelya_bundle__configuration_settings',
'name' => $this->tr->trans('Adelya', [], 'AdelyaBundle')
];
$event->setPages($pages);
}
}