replace harcoded emails with settings
This commit is contained in:
parent
2670c322e6
commit
9efd9c9b74
|
@ -7,10 +7,11 @@ use App\Core\Notification\MailNotifier;
|
||||||
use App\Form\ContactType;
|
use App\Form\ContactType;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use App\Core\Setting\SettingManager;
|
||||||
|
|
||||||
class ContactController extends PageController
|
class ContactController extends PageController
|
||||||
{
|
{
|
||||||
public function contact(MailNotifier $notifier, Request $request): Response
|
public function contact(MailNotifier $notifier, Request $request, SettingManager $settingManager): Response
|
||||||
{
|
{
|
||||||
$form = $this->createForm(ContactType::class);
|
$form = $this->createForm(ContactType::class);
|
||||||
$showForm = true;
|
$showForm = true;
|
||||||
|
@ -23,8 +24,8 @@ class ContactController extends PageController
|
||||||
$data = $form->getData();
|
$data = $form->getData();
|
||||||
|
|
||||||
$notifier
|
$notifier
|
||||||
->setFrom('subscription@deblan.fr')
|
->setFrom($settingManager->get('email_sender')->getValue())
|
||||||
->addRecipient('simon@deblan.fr')
|
->addRecipient($settingManager->get('email_contact')->getValue())
|
||||||
->setSubject('[Deblan] Nouveau message')
|
->setSubject('[Deblan] Nouveau message')
|
||||||
->setReplyTo($data['email'])
|
->setReplyTo($data['email'])
|
||||||
->notify('mail/contact.html.twig', [
|
->notify('mail/contact.html.twig', [
|
||||||
|
|
|
@ -8,6 +8,7 @@ use App\Core\EventSuscriber\EntityManagerEventSubscriber;
|
||||||
use App\Core\Notification\MailNotifier;
|
use App\Core\Notification\MailNotifier;
|
||||||
use App\Entity\Blog\Comment;
|
use App\Entity\Blog\Comment;
|
||||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||||
|
use App\Core\Setting\SettingManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class CommentEventSubscriber.
|
* class CommentEventSubscriber.
|
||||||
|
@ -18,11 +19,13 @@ class CommentEventSubscriber extends EntityManagerEventSubscriber
|
||||||
{
|
{
|
||||||
protected MailNotifier $notifier;
|
protected MailNotifier $notifier;
|
||||||
protected UrlGeneratorInterface $urlGenerator;
|
protected UrlGeneratorInterface $urlGenerator;
|
||||||
|
protected SettingManager $settingManager;
|
||||||
|
|
||||||
public function __construct(MailNotifier $notifier, UrlGeneratorInterface $urlGenerator)
|
public function __construct(MailNotifier $notifier, UrlGeneratorInterface $urlGenerator, SettingManager $settingManager)
|
||||||
{
|
{
|
||||||
$this->notifier = $notifier;
|
$this->notifier = $notifier;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
$this->settingManager = $settingManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function support(EntityInterface $entity)
|
public function support(EntityInterface $entity)
|
||||||
|
@ -38,8 +41,8 @@ class CommentEventSubscriber extends EntityManagerEventSubscriber
|
||||||
|
|
||||||
$this->notifier
|
$this->notifier
|
||||||
->init()
|
->init()
|
||||||
->setFrom('subscription@deblan.fr')
|
->setFrom($this->settingManager->get('email_sender')->getValue())
|
||||||
->addRecipient('simon@deblan.fr')
|
->addRecipient($this->settingManager->get('email_comment')->getValue())
|
||||||
->setSubject('[Deblan] Nouveau commentaire')
|
->setSubject('[Deblan] Nouveau commentaire')
|
||||||
->notify('mail/comment.html.twig', [
|
->notify('mail/comment.html.twig', [
|
||||||
'post' => $event->getEntity()->getPost(),
|
'post' => $event->getEntity()->getPost(),
|
||||||
|
|
|
@ -5,8 +5,7 @@ namespace App\EventSuscriber;
|
||||||
use App\Core\Event\Setting\SettingEvent;
|
use App\Core\Event\Setting\SettingEvent;
|
||||||
use App\Core\EventSuscriber\SettingEventSubscriber as EventSubscriber;
|
use App\Core\EventSuscriber\SettingEventSubscriber as EventSubscriber;
|
||||||
use App\Core\Setting\SettingManager;
|
use App\Core\Setting\SettingManager;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
use Symfony\Component\Form\Extension\Core\Type\EmailType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +26,10 @@ class SettingEventSubscriber extends EventSubscriber
|
||||||
{
|
{
|
||||||
$this->manager->init('blog_footer_p1', 'Pied de page', 'Soutiens', '');
|
$this->manager->init('blog_footer_p1', 'Pied de page', 'Soutiens', '');
|
||||||
$this->manager->init('blog_footer_p2', 'Pied de page', 'Signature', '');
|
$this->manager->init('blog_footer_p2', 'Pied de page', 'Signature', '');
|
||||||
|
|
||||||
|
$this->manager->init('email_sender', 'E-mail', 'Expéditeur', '');
|
||||||
|
$this->manager->init('email_contact', 'E-mail', 'Destinataire formulaire de contact', '');
|
||||||
|
$this->manager->init('email_comment', 'E-mail', 'Destinataire nouveau commentaire', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onFormInit(SettingEvent $event)
|
public function onFormInit(SettingEvent $event)
|
||||||
|
@ -35,6 +38,16 @@ class SettingEventSubscriber extends EventSubscriber
|
||||||
$builder = $data['builder'];
|
$builder = $data['builder'];
|
||||||
$entity = $data['entity'];
|
$entity = $data['entity'];
|
||||||
|
|
||||||
|
if (in_array($entity->getCode(), ['email_sender', 'email_contact', 'email_comment'])) {
|
||||||
|
$builder->add(
|
||||||
|
'value',
|
||||||
|
EmailType::class,
|
||||||
|
[
|
||||||
|
'label' => $entity->getLabel(),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if ('blog_footer_p1' === $entity->getCode()) {
|
if ('blog_footer_p1' === $entity->getCode()) {
|
||||||
$builder->add(
|
$builder->add(
|
||||||
'value',
|
'value',
|
||||||
|
@ -60,6 +73,5 @@ class SettingEventSubscriber extends EventSubscriber
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue