<?php
/**
* User: remmel
* Date: 11/3/15
* Time: 5:27 PM
*/
namespace App\Controller\Frontend;
use App\Entity\model\Contact;
use App\Form\ContactType;
use App\Service\PressReleaseService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use Symfony\Component\Routing\Annotation\Route;
class ContentController extends AbstractController {
protected PressReleaseService $pressService;
public function __construct(PressReleaseService $pressService) {
$this->pressService = $pressService;
}
/**
* @Route("/press", name="page_press")
* @Template("Default/simple/press.html.twig")
*/
public function pressPageAction() {
return [
'articles' => $this->pressService->createBlocks(),
'datetime' => $this->pressService->getDebugCreatedDate()
];
}
/**
* @Route("/contact", name="page_contact")
*/
public function contactAction(Request $request, MailerInterface $mailer) {
$contact = new Contact();
$form = $this->createForm(ContactType::class, $contact);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$message = (new Email())
->subject('New Contact : '.$contact->getSubject())
->from('remy.cloutrier@gmail.com')
->to('contact@comparabus.com')
->replyTo($contact->getEmail())
->html(
'<b>'.$contact->getName().':</b><br />'.$contact->getMessage(),
'text/html'
);
$mailer->send($message);
$this->addFlash('notice','contactpage.sent');
}
return $this->render(
'Default/simple/contact.html.twig',[
'form' => $form->createView(),
]
);
}
}