src/Controller/Front/FrontPageController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Email;
  4. use App\Entity\FrontPage;
  5. use App\Form\ContactType;
  6. use App\Repository\EmailRepository;
  7. use App\Service\EmailService;
  8. use App\Service\FrontService;
  9. use App\Service\ParameterService;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. class FrontPageController extends AbstractController
  15. {
  16.     public function __construct(
  17.         private readonly FrontService                       $frontService,
  18.         private readonly ParameterService                   $parameterService,
  19.     ){}
  20.     #[Route('/contact'name'app_front_contact')]
  21.     public function contact(Request                   $request,
  22.                             EmailService              $emailService,
  23.                             EmailRepository           $emailRepository,
  24.                             ParameterService          $parameterService
  25.     ): Response
  26.     {
  27.         $form $this->createForm(ContactType::class);
  28.         $form->handleRequest($request);
  29.         if($form->isSubmitted() && $form->isValid()) {
  30.             $from $parameterService->getContactSMTPAddressFrom();
  31.             $to trim($request->request->get('email'));
  32.             $societyName $parameterService->getSocietyInfos()['name'];
  33.             $subject $societyName" Contact Message ";
  34.             $content $this->renderView('email/contact.html.twig', ['data' => $form->getData()]);
  35.             // compose and save Email
  36.             $email $emailService->composeMail($from$to$subject$contentnull$from);
  37.             $email->setType(Email::CONTACT);
  38.             $emailRepository->save($emailtrue);
  39.             return $this->redirectToRoute('app_front_contact'); // success send page
  40.         }
  41.         return $this->renderForm('front/subpage/contact.html.twig', [
  42.             'form' => $form,
  43.             'society'           => $this->parameterService->getSocietyParameters(),
  44.             'social_networks'   => $this->frontService->getSocialNetworks(),
  45.             'agencies'          => $this->frontService->getAgencies(),
  46.             'currencies'        => $this->frontService->getCurrencies(),
  47.             'home'              => null,
  48.             'tracking_tools' => $this->frontService->getTrackingTools()
  49.         ]);
  50.     }
  51.     #[Route('/infos/{slug}'name'app_main_static_page'methods: ['GET'])]
  52.     public function getFrontPage(FrontPage $frontPage): Response
  53.     {
  54.         $contentPage $frontPage->getContent();
  55.         $titlePage $frontPage->getTitle();
  56.         return $this->render('front/subpage/static_page.html.twig', [
  57.             'content'           => $contentPage,
  58.             'title'             => $titlePage,
  59.             'society'           => $this->parameterService->getSocietyParameters(),
  60.             'social_networks'   => $this->frontService->getSocialNetworks(),
  61.             'agencies'          => $this->frontService->getAgencies(),
  62.             'currencies'        => $this->frontService->getCurrencies(),
  63.             'home'              => null,
  64.         ]);
  65.     }
  66. }