<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Response;
// use Symfony\Component\Routing\Annotation\Route;
// use App\Entity\SiteContact;
use App\Form\Type\SiteContactType;
// use App\Entity\SiteNewsletter;
// use App\Entity\SiteShop;
// use App\Entity\Customer\Customer;
// use App\Form\Type\SiteNewsletterType;
// use App\Services\SendInBlueService;
use App\Services\NewsletterService;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
class SiteContactController extends AbstractController
{
public function indexAction(
Request $request,
EntityManagerInterface $entityManager
): Response
{
// $siteContact = new SiteContact();
$form = $this->createForm(SiteContactType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()){
$data = $form->getData();
// dump($data);
$entityManager->persist($data);
$entityManager->flush();
$this->addFlash('success', 'Votre demande est envoyée');
}
return $this->render('contact.html.twig', [
'form' => $form->createView()
]);
}
public function getAccountAction(
Request $request,
EntityManagerInterface $entityManager,
NewsletterService $newsletterService
)
{
$form = $newsletterService->generateForm(trim($request->get('email')), $entityManager, false);
return $this->render('newsletter/formall.html.twig', [
'form' => $form->createView()
]);
}
public function newsletterAction(
Request $request,
EntityManagerInterface $entityManager,
NewsletterService $newsletterService
): Response
{
$form = $newsletterService->getForm($request, $entityManager);
if($request->getMethod() == 'POST') {
return $this->redirect($request->getUri());
}
$formEmail = $this->renderView('newsletter/formemail.html.twig', ['form' => $form, 'hide' => false]);
$formAll = $this->renderView('newsletter/formall.html.twig', ['form' => $form]);
$formView = $this->renderView('newsletter/form.html.twig', [
'formEmail' => $formEmail,
"formAll" => $formAll,
'form' => $form,
'path' => 'app_formulairenewsletter'
]);
return $this->render('newsletter.html.twig', [
"formView" => $formView
]);
}
}