<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Form\ContactType;
use App\Notification\ContactNotification;
use App\Repository\SectionTitleRepository;
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\Routing\Annotation\Route;
class ContactController extends AbstractController
{
/**
* @Route("/nous-contacter", name="app_contact")
*/
public function index(SectionTitleRepository $sectionTitleRepository, Request $request, ContactNotification $notification, SectiontitleRepository $postRepo): 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);
$this->addFlash('success', 'Votre message a bien été envoyé !');
return $this->redirectToRoute('app_contact');
}
return $this->render('contact/index.html.twig', [
'contactTitle' => $title,
'form' => $form->createView()
]);
}
}