<?php
/**
* @author Quentin CHATELAIN (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\PimBundle\EventSubscriber;
use App\Event\AdditionalJavascriptsEvent;
use App\Services\CheckBundleInstall;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Security;
class AdditionalJavascriptsSubscriber implements EventSubscriberInterface
{
private RouterInterface $router;
/**
* @var Security
*/
private Security $security;
/**
* @param RouterInterface $router
* @param Security $security
*/
public function __construct(RouterInterface $router, Security $security)
{
$this->router = $router;
$this->security = $security;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
AdditionalJavascriptsEvent::NAME => 'onLoad'
];
}
/**
* @param AdditionalJavascriptsEvent $event
* @return void
*/
public function onLoad(AdditionalJavascriptsEvent $event): void
{
$javascripts = [
[
'entry' => 'pim_bundle',
'controllers' => [
[
'name' => 'pim--edit-fields',
'routes' => [
'pim_bundle__mass_management'
]
],
[
'name' => 'pim--calc-price-with-margin',
'routes' => [
'pim_bundle__mass_management'
]
]
]
]
];
if (CheckBundleInstall::exist('categories-bundle')) {
$javascripts[0]['controllers'][] = [
'name' => 'pim--manage-categories',
'routes' => [
'pim_bundle__mass_management'
],
];
}
if ($this->security->isGranted('ROLE__PIM__ADMIN')) {
$javascripts[0]['controllers'][] = [
'name' => 'pim--sequential-modification',
'routes' => [
'products_bundle__product_sheet'
],
'options' => [
'data-sequential-modification-url' => $this->router->generate(
'pim_bundle__sequential_modification_check'
)
]
];
}
$event->addJavascripts($javascripts);
}
}