src/Controller/Frontend/ContentController.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * User: remmel
  4.  * Date: 11/3/15
  5.  * Time: 5:27 PM
  6.  */
  7. namespace App\Controller\Frontend;
  8. use App\Entity\model\Contact;
  9. use App\Form\ContactType;
  10. use App\Service\PressReleaseService;
  11. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Mailer\MailerInterface;
  15. use Symfony\Component\Mime\Email;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class ContentController extends AbstractController {
  18.     protected PressReleaseService $pressService;
  19.     public function __construct(PressReleaseService $pressService) {
  20.         $this->pressService $pressService;
  21.     }
  22.     /**
  23.      * @Route("/press", name="page_press")
  24.      * @Template("Default/simple/press.html.twig")
  25.      */
  26.     public function pressPageAction() {
  27.         return [
  28.             'articles' => $this->pressService->createBlocks(),
  29.             'datetime' => $this->pressService->getDebugCreatedDate()
  30.         ];
  31.     }
  32.     /**
  33.      * @Route("/contact", name="page_contact")
  34.      */
  35.     public function contactAction(Request $requestMailerInterface $mailer) {
  36.         $contact = new Contact();
  37.         $form $this->createForm(ContactType::class, $contact);
  38.         $form->handleRequest($request);
  39.         if ($form->isSubmitted() && $form->isValid()) {
  40.             $message = (new Email())
  41.                 ->subject('New Contact : '.$contact->getSubject())
  42.                 ->from('remy.cloutrier@gmail.com')
  43.                 ->to('contact@comparabus.com')
  44.                 ->replyTo($contact->getEmail())
  45.                 ->html(
  46.                     '<b>'.$contact->getName().':</b><br />'.$contact->getMessage(),
  47.                     'text/html'
  48.                 );
  49.             $mailer->send($message);
  50.             $this->addFlash('notice','contactpage.sent');
  51.         }
  52.         return $this->render(
  53.             'Default/simple/contact.html.twig',[
  54.                 'form' => $form->createView(),
  55.             ]
  56.         );
  57.     }
  58. }