From: Raphaƫl Gertz Date: Wed, 24 Feb 2021 00:04:38 +0000 (+0100) Subject: Switch to named form X-Git-Tag: 0.2.1~35 X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/airbundle/commitdiff_plain/58c6e18ae869acfd9e24c73e1296d8499856fcdc Switch to named form Rename organizer to user --- diff --git a/Controller/SnippetController.php b/Controller/SnippetController.php index 6335b1f..accbae0 100644 --- a/Controller/SnippetController.php +++ b/Controller/SnippetController.php @@ -3,6 +3,7 @@ namespace Rapsys\AirBundle\Controller; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; @@ -26,13 +27,22 @@ class SnippetController extends DefaultController { //Prevent non-guest to access here $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator->trans('Guest')])); - //Create ApplicationType form - $form = $this->createForm('Rapsys\AirBundle\Form\SnippetType', null, [ - //Set the action - 'action' => $this->generateUrl('rapsys_air_snippet_add'), - //Set the form attribute - 'attr' => [] - ]); + //Create SnippetType form + $form = $this->container->get('form.factory')->createNamed( + //Set name + 'snipped_'.$request->getLocale().'_'.$request->get('location'), + //Set type + 'Rapsys\AirBundle\Form\SnippetType', + //Set data + null, + //Set options + [ + //Set the action + 'action' => $this->generateUrl('rapsys_air_snippet_add', ['location' => $request->get('location')]), + //Set the form attribute + 'attr' => [] + ] + ); //Refill the fields in case of invalid form $form->handleRequest($request); @@ -118,7 +128,7 @@ class SnippetController extends DefaultController { unset($route['_route'], $route['_controller']); //Check if snippet view route - if ($name == 'rapsys_air_organizer_view' && !empty($route['id'])) { + if ($name == 'rapsys_air_user_view' && !empty($route['id'])) { //Replace id $route['id'] = $snippet->getUser()->getId(); //Other routes @@ -163,13 +173,22 @@ class SnippetController extends DefaultController { throw $this->createNotFoundException($this->translator->trans('Unable to find snippet: %id%', ['%id%' => $id])); } - //Create ApplicationType form - $form = $this->createForm('Rapsys\AirBundle\Form\SnippetType', $snippet, [ - //Set the action - 'action' => $this->generateUrl('rapsys_air_snippet_edit', ['id' => $id]), - //Set the form attribute - 'attr' => [] - ]); + //Create SnippetType form + $form = $this->container->get('form.factory')->createNamed( + //Set name + 'snipped_'.$request->getLocale().'_'.$snippet->getLocation()->getId(), + //Set type + 'Rapsys\AirBundle\Form\SnippetType', + //Set data + $snippet, + //Set options + [ + //Set the action + 'action' => $this->generateUrl('rapsys_air_snippet_edit', ['id' => $id]), + //Set the form attribute + 'attr' => [] + ] + ); //Refill the fields in case of invalid form $form->handleRequest($request); @@ -246,7 +265,7 @@ class SnippetController extends DefaultController { unset($route['_route'], $route['_controller']); //Check if snippet view route - if ($name == 'rapsys_air_organizer_view' && !empty($route['id'])) { + if ($name == 'rapsys_air_user_view' && !empty($route['id'])) { //Replace id $route['id'] = $snippet->getUser()->getId(); //Other routes