/** * @Security("has_role('ROLE_OKTOLAB_USER')") * @Route("/answer/{comment}", name="oktothek_answer_comment") * @Template() */ public function answerCommentAction(Request $request, Comment $comment) { $answer = new Comment(); $commentForm = $this->createForm(CommentType::class, $answer, ['action' => $this->generateUrl('oktothek_answer_comment', ['comment' => $comment->getId()])]); $commentForm->add('submit', SubmitType::class, ['label' => 'oktothek.comment_reply_button', 'attr' => ['class' => 'btn btn-primary']]); if ($request->getMethod() == "POST") { $commentForm->handleRequest($request); if ($commentForm->isValid()) { $answer->setUser($this->get('security.context')->getToken()->getUser()); $answer->setReferer($comment->getReferer()); $answer->setParent($comment); $comment->addChild($answer); $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->persist($answer); $em->flush(); $this->get('session')->getFlashBag()->add('success', 'oktothek.comment_create_success'); return $this->redirect($request->headers->get('referer')); } $this->get('session')->getFlashBag()->add('error', 'oktothek.comment_create_error'); } return ['commentForm' => $commentForm->createView()]; }