<?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\PlanningBundle\EventSubscriber;
use App\Event\DashboardWidgetsEvent;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class DashboardSubscriber implements EventSubscriberInterface
{
/**
* @var Security
*/
private Security $security;
/**
* @param Security $security
*/
public function __construct(
Security $security
) {
$this->security = $security;
}
/**
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
DashboardWidgetsEvent::NAME => 'onLoad'
];
}
/**
* @param DashboardWidgetsEvent $event
* @return void
*/
public function onLoad(DashboardWidgetsEvent $event): void
{
if ($this->security->isGranted('ROLE__PLANNING__READ_ONLY')) {
$event->addWidget('planning_bundle__dashboard');
}
}
}