/** * @Route("/client/new", name="new-client") * @Security("has_role('ROLE_USER')") */ public function newClientAction(Request $request) { $profiles = $this->get('voicein_helper')->getProfiles(); $clients = $this->get('voicein_helper')->getClients(); if (!$profiles) { $this->addFlash('notice', 'You\'ve been redirected to New Profile page. Please add a profile before adding a client.'); return $this->redirectToRoute('new-profile'); } $user = $this->container->get('security.context')->getToken()->getUser(); $client = new Client(); $client->setUser($user->getId()); $form = $this->createForm($this->get('form_client_type'), $client); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($client); $em->flush(); $this->addFlash('success', 'Client has been added.'); return $this->redirectToRoute('clients'); } return $this->render('default/new-client.html.twig', array('form' => $form->createView())); }
/** * {@inheritDoc} */ public function setUser(\AppBundle\Entity\User $user = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setUser', array($user)); return parent::setUser($user); }