/** * @Route("/budget/{budget_id}/invitation/new", name="sb_invitation_new", requirements={"budget_id": "\d+"}) */ public function newAction(Request $request, $budget_id) { $budget = $this->get('app.checker')->budget($this->getUser(), $budget_id, false); $invitation = new Invitation(); $invitation->setBudget($budget); $form = $this->createForm(InvitationType::class, $invitation); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $invitation->setUser($this->getUser()); $action = Action::newInvitation($budget, $this->getUser(), $invitation->toArray()); $em = $this->getDoctrine()->getManager(); $em->persist($invitation); $em->persist($action); $em->flush(); $this->addFlash('notice', $this->get('translator')->trans('invitation.createsuccessful')); return $this->redirectToRoute('sb_budget_show', array('id' => $budget->getId())); } return $this->render('invitation/form.html.twig', array('form' => $form->createView(), 'budget' => $budget)); }