src/Controller/Front/FrontPageController.php line 62

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