src/EventSubscriber/PageSubscriber.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use App\Event\Page\PageCreatedEvent;
  4. use App\Repository\RolesRepository;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class PageSubscriber implements EventSubscriberInterface
  7. {
  8.     /**
  9.      * @var RolesRepository
  10.      */
  11.     private $rolesRepository;
  12.     public function __construct(RolesRepository $rolesRepository)
  13.     {
  14.         $this->rolesRepository $rolesRepository;
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             PageCreatedEvent::class => ['onPageCreated'100],
  20.         ];
  21.     }
  22.     public function onPageCreated(PageCreatedEvent $event)
  23.     {
  24.         // On ajoute automatiquement la page à l'admin
  25.         $page $event->getPage();
  26.         $profilAdmin $this->rolesRepository->findOneBy(['identifiant' => 'ROLE_ADMIN']);
  27.         $page->addRole($profilAdmin);
  28.     }
  29. }