]> Raphaël G. Git Repositories - blogbundle/blobdiff - Controller/DefaultController.php
Move index route to context to prevent automatic conversion
[blogbundle] / Controller / DefaultController.php
index 57703dbd6c1bc6194d341972108c3aae4fd5b009..962c0b8636c279198844bf2ec6f76440a2a28f22 100644 (file)
@@ -33,7 +33,7 @@ class DefaultController extends AbstractController {
         */
        public function about(Request $request): Response {
                //Set page
-               $this->context['title'] = $this->translator->trans('About');
+               $this->context['title']['page'] = $this->translator->trans('About');
 
                //Set description
                $this->context['description'] = $this->translator->trans('Welcome to raphaël\'s developer diary about page');
@@ -74,7 +74,7 @@ class DefaultController extends AbstractController {
         */
        public function contact(Request $request): Response {
                //Set title
-               $this->context['title'] = $this->translator->trans('Contact');
+               $this->context['title']['page'] = $this->translator->trans('Contact');
 
                //Set description
                $this->context['description'] = $this->translator->trans('Welcome to raphaël\'s developer diary contact page');
@@ -99,8 +99,8 @@ class DefaultController extends AbstractController {
 
                //Create the form according to the FormType created previously.
                //And give the proper parameters
-               $form = $this->createForm('Rapsys\BlogBundle\Form\ContactType', $data, [
-                       'action' => $this->generateUrl('rapsys_blog_contact'),
+               $form = $this->createForm('Rapsys\PackBundle\Form\ContactType', $data, [
+                       'action' => $this->generateUrl('rapsysblog_contact'),
                        'method' => 'POST'
                ]);
 
@@ -140,17 +140,15 @@ class DefaultController extends AbstractController {
                                        //Send message
                                        $this->mailer->send($message);
 
+                                       //Add verification notice
+                                       $this->addFlash('notice', $this->translator->trans('Your message has been sent'));
+
                                        //Redirect on the same route with sent=1 to cleanup form
-                                       return $this->redirectToRoute($request->get('_route'), ['sent' => 1]+$request->get('_route_params'));
+                                       return $this->redirectToRoute($request->get('_route'), $request->get('_route_params'));
                                //Catch obvious transport exception
                                } catch(TransportExceptionInterface $e) {
-                                       if ($message = $e->getMessage()) {
-                                               //Add error message mail unreachable
-                                               $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%: %message%', ['%mail%' => $this->config['contact']['mail'], '%message%' => $this->translator->trans($message)])));
-                                       } else {
-                                               //Add error message mail unreachable
-                                               $form->get('mail')->addError(new FormError($this->translator->trans('Unable to contact: %mail%', ['%mail%' => $this->config['contact']['mail']])));
-                                       }
+                                       //Add error message mail unreachable
+                                       $form->get('mail')->addError(new FormError($this->translator->trans('Unable to reach account')));
                                }
                        }
                //With logged user
@@ -180,7 +178,7 @@ class DefaultController extends AbstractController {
                }
 
                //Render template
-               return $this->render('@RapsysBlog/form/contact.html.twig', ['contact' => $form->createView(), 'sent' => $request->query->get('sent', 0)]+$this->context, $response);
+               return $this->render('@RapsysBlog/form/contact.html.twig', ['contact' => $form->createView()]+$this->context, $response);
        }
 
        /**
@@ -266,7 +264,7 @@ class DefaultController extends AbstractController {
                );
 
                //Set title
-               $this->context['title'] = $this->translator->trans('Home');
+               $this->context['title']['page'] = $this->translator->trans('Home');
 
                //Set description
                $this->context['description'] = $this->translator->trans('Welcome to raphaël\'s developer diary');