src/Aqarmap/Bundle/MainBundle/Controller/FeedbackController.php line 87
<?phpnamespace Aqarmap\Bundle\MainBundle\Controller;use Aqarmap\Bundle\MainBundle\Constant\FeedbackSource;use Aqarmap\Bundle\MainBundle\Entity\Feedback;use Aqarmap\Bundle\MainBundle\Event\FeedbackEvent;use Aqarmap\Bundle\MainBundle\Form\FeedbackType;use Doctrine\ORM\EntityManagerInterface;use Egulias\EmailValidator\EmailValidator;use Egulias\EmailValidator\Validation\RFCValidation;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\EventDispatcher\EventDispatcherInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Attribute\Route;use Symfony\Contracts\Translation\TranslatorInterface;class FeedbackController extends AbstractController{public function __construct(private readonly TranslatorInterface $translator, private readonly EventDispatcherInterface $eventDispatcher){}#[Route(path: '/feedback', name: 'aqarmap_feedback_post', methods: ['POST'])]public function post(Request $request, EntityManagerInterface $em){$form = $this->createForm(FeedbackType::class, $entity = new Feedback(), ['action' => $this->generateUrl('aqarmap_feedback_post'),'method' => 'POST',]);$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$validator = new EmailValidator();$isValidEmail = $validator->isValid($entity->getEmail(), new RFCValidation());if (!$isValidEmail) {$this->addFlash('danger',$this->translator->trans('static.invalid_email'));return $this->redirectToRoute('aqarmap_feedback_get');}// Set collected user data$entity->setCollectedData(array_merge(['referer' => $form->get('referer')->getData() ?: $request->headers->get('referer'),], $request->attributes->get('_browser')));$entity->setIp($request->getClientIp());$entity->setSource(FeedbackSource::WEB);$em->persist($entity);$this->eventDispatcher->dispatch(new FeedbackEvent($entity), 'aqarmap.feedback.send_message');$userMail = $form->get('email')->getData();} else {// Set error flash message$request->getSession()->getFlashBag()->add('danger',$this->translator->trans('static.problem_error_message'));return $this->redirect($request->headers->get('referer') ?: $this->generateUrl('homepage'));}return $this->render('@AqarmapMain/Feedback/post.html.twig', ['userMail' => $userMail,]);}#[Route(path: '/feedback', name: 'aqarmap_feedback_get', methods: ['GET'])]public function feedback(Request $request): Response{$form = $this->createForm(FeedbackType::class, new Feedback(), ['action' => $this->generateUrl('aqarmap_feedback_post'),'method' => 'POST',]);// Set the referrer URLif (!$form->get('referer')->getData()) {$form->get('referer')->setData($request->headers->get('referer'));}return $this->render('@AqarmapMain/Feedback/feedbackForm.html.twig', ['form' => $form,]);}}