<?php
namespace App\Controller;
use App\Entity\Contact;
use App\Form\ContactType;
use App\Notification\ContactNotification;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\ImagebackgroundRepository;
class ContactController extends AbstractController
{
/**
* @var ImagebackgroundRepository
*/
private $i_repository;
public function __construct(ImagebackgroundRepository $i_repository)
{
$this->i_repository = $i_repository;
}
/**
* @Route("/contact", name="contact")
* @return Response
*/
public function contact(Request $request, ContactNotification $notification): Response
{
$image = $this->i_repository->find(1);
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$notification->notify($contact);
$this->addFlash('success', 'votre email a bien été envoyé ');
return $this->redirectToRoute('contact');
}
return $this->render('pages/contact.html.twig', [
'current_menu' => 'contact',
'form' => $form->createView(),
'img' => $image
]);
}
}