55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\EventSuscriber\Blog;
|
|
|
|
use App\Core\Entity\EntityInterface;
|
|
use App\Core\Event\EntityManager\EntityManagerEvent;
|
|
use App\Core\EventSuscriber\EntityManagerEventSubscriber;
|
|
use App\Core\Notification\MailNotifier;
|
|
use App\Entity\Blog\Comment;
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
|
|
|
/**
|
|
* class CommentEventSubscriber.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
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')
|
|
;
|
|
}
|
|
}
|