src/Controller/HomeController.php line 59

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Message;
  4. use App\Form\ContactType;
  5. use App\Repository\PackRepository;
  6. use App\Service\MailService;
  7. use App\Service\PaginationService;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class HomeController extends AbstractController
  14. {
  15.     #[Route('/'name'app_home'methods: ['GET''POST'])]
  16.     public function save(Request                $request,
  17.                          EntityManagerInterface $manager,
  18.                          MailService            $mailService,
  19.                          PackRepository $repository,PaginationService $service
  20.     ): Response
  21.     {
  22.         $parameters $service->paginate($request$repository);
  23.         $message = new Message();
  24.         $form $this->createForm(ContactType::class, $message);
  25.         $form->handleRequest($request);
  26.         if ($form->isSubmitted() && $form->isValid()) {
  27. //            dd($form);
  28.             $manager->persist($message);
  29.             $manager->flush();
  30.             //send email to the admin
  31.             $mailService->sendMail(
  32.                 'contact@arctri.kayagro.com',
  33.                 'contact@arctri.kayagro.com',
  34.                 'emails/Message/contact.html.twig',
  35.                 [
  36.                     'message' => $message,
  37.                 ]
  38.             );
  39.             $this->addFlash(
  40.                 'success',
  41.                 'Message envoyé'
  42.             );
  43.             return $this->redirectToRoute("app_home");
  44.         }
  45. //@Todo En cas d'erreur,  renvoyer l'utilisateur au niveau du formulaire de contact
  46. //        Faire l'intégration avec Turbo aussi pour le formulaire
  47.         return $this->render('pages/app/index.html.twig',$parameters +  [
  48.             'contactForm' => $form
  49.         ]);
  50.     }
  51.     #[Route('/cgu'name'app_cgu'methods: ['GET'])]
  52.     public function cgu()
  53.     {
  54.         return $this->render('pages/app/cgu.html.twig');
  55.     }
  56. }