<?php declare(strict_types=1);
namespace App\Controller\StaticPage;
use App\Email\Contact;
use App\Form\Type\ContactType;
use Sindrive\EmailSenderBundle\Service\EmailSender;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactController extends AbstractController
{
private EmailSender $sender;
private TranslatorInterface $translator;
public function form(Request $request): Response
{
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/** @var array{text: string, subject: string, name: string, email: string} $data */
$data = $form->getData();
$this->sender->sendType(new Contact($data));
$message = $this->translator->trans('contact.message', [], 'static_pages');
/** @var Session $session */
$session = $request->getSession();
$session->getFlashBag()->add('success_messages', $message);
return $this->redirectToRoute('contact');
}
return $this->render('static/contact.html.twig', ['form' => $form->createView()]);
}
/**
* @required
*/
public function setSender(EmailSender $sender): void
{
$this->sender = $sender;
}
/**
* @required
*/
public function setTranslator(TranslatorInterface $translator): void
{
$this->translator = $translator;
}
}