<?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\ColissimoBundle\EventSubscriber;
use App\Event\MenuConfigurationPageEvent;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Bluue\ShipmentsBundle\Event\MenuConfigurationPageShipmentsEvent;
class ConfigureShipmentsMenuSubscriber implements EventSubscriberInterface
{
private TranslatorInterface $tr;
public function __construct(
TranslatorInterface $tr
) {
$this->tr = $tr;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
MenuConfigurationPageShipmentsEvent::NAME => 'onLoad',
MenuConfigurationPageEvent::NAME => 'onLoad2'
];
}
/**
* @param MenuConfigurationPageShipmentsEvent $event
* @return void
*/
public function onLoad(MenuConfigurationPageShipmentsEvent $event): void
{
$pages = $event->getPages();
$pages[] = [
'id' => 'colissimo_bundle__configuration',
'name' => $this->tr->trans('Colissimo', [], 'ColissimoBundle')
];
$event->setPages($pages);
}
/**
* @param MenuConfigurationPageEvent $event
* @return void
*/
public function onLoad2(MenuConfigurationPageEvent $event): void
{
$pages = $event->getPages();
$keyShipmentsMenu = array_search('shipments_bundle__configuration', array_column($pages, 'id'));
if (is_numeric($keyShipmentsMenu)) {
$pages[$keyShipmentsMenu]['subpages'][] = ['id' => 'colissimo_bundle__configuration'];
$event->setPages($pages);
}
}
}