src/Controller/HomeController.php line 59
<?php
namespace App\Controller;
use App\Entity\Message;
use App\Form\ContactType;
use App\Repository\PackRepository;
use App\Service\MailService;
use App\Service\PaginationService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
#[Route('/', name: 'app_home', methods: ['GET', 'POST'])]
public function save(Request $request,
EntityManagerInterface $manager,
MailService $mailService,
PackRepository $repository,PaginationService $service
): Response
{
$parameters = $service->paginate($request, $repository);
$message = new Message();
$form = $this->createForm(ContactType::class, $message);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// dd($form);
$manager->persist($message);
$manager->flush();
//send email to the admin
$mailService->sendMail(
'contact@arctri.kayagro.com',
'contact@arctri.kayagro.com',
'emails/Message/contact.html.twig',
[
'message' => $message,
]
);
$this->addFlash(
'success',
'Message envoyé'
);
return $this->redirectToRoute("app_home");
}
//@Todo En cas d'erreur, renvoyer l'utilisateur au niveau du formulaire de contact
// Faire l'intégration avec Turbo aussi pour le formulaire
return $this->render('pages/app/index.html.twig',$parameters + [
'contactForm' => $form
]);
}
#[Route('/cgu', name: 'app_cgu', methods: ['GET'])]
public function cgu()
{
return $this->render('pages/app/cgu.html.twig');
}
}