src/Controller/ContactController.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Contact;
  4. use App\Form\ContactType;
  5. use App\Notification\ContactNotification;
  6. use App\Repository\SectionTitleRepository;
  7. use App\Service\SendMailService;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Mailer\MailerInterface;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class ContactController extends AbstractController
  14. {
  15.     /**
  16.      * @Route("/nous-contacter", name="app_contact")
  17.      */
  18.     public function index(SectionTitleRepository $sectionTitleRepositoryRequest $requestContactNotification $notificationSectiontitleRepository $postRepo): Response
  19.     {
  20.         $title $sectionTitleRepository->findTitleByTag('contact_index');
  21.         $contact = new Contact;
  22.         $form $this->createForm(ContactType::class, $contact);
  23.         $form->handleRequest($request);
  24.         if ($form->isSubmitted() && $form->isValid()) {
  25.             $notification->notify($contact);
  26.             $this->addFlash('success''Votre message a bien été envoyé !');
  27.             return $this->redirectToRoute('app_contact');
  28.         }
  29.         return $this->render('contact/index.html.twig', [
  30.             'contactTitle' => $title,
  31.             'form' => $form->createView()
  32.         ]);
  33.     }
  34. }