<?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\ProductsBundle\EventSubscriber;
use App\Event\MenuConfigurationPageEvent;
use App\Services\CheckBundleInstall;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ConfigureSubMenuSubscriber implements EventSubscriberInterface
{
/**
* @var TranslatorInterface
*/
private TranslatorInterface $tr;
/**
* @var Security
*/
private Security $security;
/**
* @var CheckBundleInstall
*/
private CheckBundleInstall $checkBundleInstall;
/**
* @param TranslatorInterface $tr
* @param Security $security
* @param CheckBundleInstall $checkBundleInstall
*/
public function __construct(
TranslatorInterface $tr,
Security $security,
CheckBundleInstall $checkBundleInstall
) {
$this->tr = $tr;
$this->security = $security;
$this->checkBundleInstall = $checkBundleInstall;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
MenuConfigurationPageEvent::NAME => 'onLoad'
];
}
/**
* @param MenuConfigurationPageEvent $event
* @return void
*/
public function onLoad(MenuConfigurationPageEvent $event): void
{
if ($this->security->isGranted('ROLE__CATALOG__ADMIN')) {
$pages = $event->getPages();
$subpages = [
['id' => 'products_bundle__configuration_settings'],
['id' => 'products_bundle__configuration_eco_part_group_list'],
['id' => 'products_bundle__configuration_eco_part_list'],
['id' => 'products_bundle__configuration_shared_catalog'],
['id' => 'products_bundle__configuration_attachment_list']
];
if ($this->checkBundleInstall->exist('categories-bundle')) {
$subpages[] = ['id' => 'categories_bundle__configuration'];
}
$pages[] = [
'id' => 'products_bundle__configuration_settings',
'name' => $this->tr->trans('Catalog Module', [], 'ProductsBundle'),
'subpages' => $subpages
];
$event->setPages($pages);
}
}
}