src/Controller/Marketplace/ContactController.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Marketplace;
  3. use App\Entity\Workshop;
  4. use App\Form\Marketplace\ContactType;
  5. use App\Service\EmailService;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class ContactController extends AbstractController
  12. {
  13.     /**
  14.      * @var emailService
  15.      */
  16.     private $emailService;
  17.     /**
  18.      * @var EntityManagerInterface
  19.      */
  20.     private $entityManagerInterface;
  21.     public function __construct(EmailService $emailServiceEntityManagerInterface $em)
  22.     {
  23.         $this->emailService $emailService;
  24.         $this->em $em;
  25.     }
  26.     /**
  27.      * @Route("/contact/", name="app_contact")
  28.      */
  29.     public function index(Request $request): Response
  30.     {
  31.         $workshop null;
  32.         if (!empty($request->query->get('from'))) {
  33.            $workshop $this->em->getRepository(Workshop::class)->find($request->query->get('from'));
  34.         }
  35.         $form $this->createForm(ContactType::class);
  36.         $form->handleRequest($request);
  37.         if ($form->isSubmitted() && $form->isValid()) {
  38.             $data $form->getData();
  39.             if (!empty($workshop)) {
  40.                 $data['workshopName'] = $workshop->getName();
  41.             }
  42.             $this->emailService->sendMarketplaceMessage($data);
  43.             $this->emailService->sendMarketplaceMessageConfirmation($data);
  44.             $this->addFlash('success''Votre message a bien été envoyé');
  45.         }
  46.         return $this->render('marketplace/contact/index.html.twig', [
  47.             'contactForm' => $form->createView()
  48.         ]);
  49.     }
  50. }