*/ class CommentEventSubscriber extends EntityManagerEventSubscriber { protected MailNotifier $notifier; protected UrlGeneratorInterface $urlGenerator; public function __construct(MailNotifier $notifier, UrlGeneratorInterface $urlGenerator) { $this->notifier = $notifier; $this->urlGenerator = $urlGenerator; } public function support(EntityInterface $entity) { return $entity instanceof Comment; } public function onCreate(EntityManagerEvent $event) { if (!$this->support($event->getEntity())) { return; } $this->notifier ->init() ->addRecipient('simon@deblan.fr') ->setSubject('[Deblan] Nouveau commentaire') ->notify('mail/comment.html.twig', [ 'post' => $event->getEntity()->getPost(), 'links' => [ 'post' => $this->urlGenerator->generate('blog_menu_post', [ 'post' => $event->getEntity()->getPost()->getId(), 'slug' => $event->getEntity()->getPost()->getSlug(), ], UrlGeneratorInterface::ABSOLUTE_URL).'#review-'.$event->getEntity()->getId(), ], ], 'text/plain') ; } }