From c037a76651b33b5e8212ae5fdb9172ab0455509d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 14 Mar 2019 19:20:02 +0100 Subject: [PATCH] Use /part/new route for creating a new part, and allow to use cid GET param to specify the category in which the part should be created. --- src/Controller/PartController.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 98c3c74f..8eecccb0 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -50,7 +50,7 @@ class PartController extends AbstractController /** * @Route("/part/{id}/info", name="part_info") - * @Route("/part/{id}") + * @Route("/part/{id}", requirements={"id"="\d+"}) */ public function show(Part $part, AttachmentFilenameService $attachmentFilenameService) { @@ -65,7 +65,7 @@ class PartController extends AbstractController } /** - * @Route("/part/{id}/edit", name="part_edit", requirements={"id"="\d+"}) + * @Route("/part/{id}/edit", name="part_edit") * * @param Part $part * @return \Symfony\Component\HttpFoundation\Response @@ -90,14 +90,17 @@ class PartController extends AbstractController } /** - * @Route("/parts/new", name="part_new") + * @Route("/part/new", name="part_new") * * @return \Symfony\Component\HttpFoundation\Response */ public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator) { $new_part = new Part(); - $category = $em->find(Category::class, 1); + + $cid = $request->get('cid', 1); + + $category = $em->find(Category::class, $cid); $new_part->setCategory($category); $form = $this->createForm(PartType::class, $new_part);