<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Form\ContactType;
use App\Notification\ContactNotification;
use App\Repository\SectionTitleRepository;
use App\Repository\TitlesRepository;
use App\Service\SendMailService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Routing\Annotation\Route;
class ContactController extends AbstractController
{
/**
* @Route("/{_locale<%app.supported_locales%>}/contact", name="app_contact")
*/
public function index(TitlesRepository $sectionTitleRepository, Request $request, ContactNotification $notification, SectiontitleRepository $postRepo, NotifierInterface $notifier): Response
{
$title = $sectionTitleRepository->findTitleByTag('contact_index');
$contact = new Contact;
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$notification->notify($contact);
$notifier->send(new Notification('Votre message a bien été envoyé. Nous vous contacterons sous peu.', ['browser']));
return $this->redirectToRoute('app_contact');
}
return $this->render('contact/index.html.twig', [
'contactTitle' => $title,
'form' => $form->createView()
]);
}
}