/** * @Route("/contrat/{id}/markdown", name="contrat_markdown") * @ParamConverter("contrat", class="AppBundle:Contrat") */ public function markdownAction(Request $request, Contrat $contrat) { $dm = $this->get('doctrine_mongodb')->getManager(); if (!$contrat->getMarkdown()) { $contrat->setMarkdown($this->renderView('contrat/contrat.markdown.twig', array('contrat' => $contrat))); $dm->persist($contrat); $dm->flush(); } $formMarkdown = $this->createForm(new ContratMarkdownType(), $contrat, array('action' => $this->generateUrl('contrat_markdown', array('id' => $contrat->getId())), 'method' => 'POST')); $formMarkdown->handleRequest($request); if ($formMarkdown->isSubmitted() && $formMarkdown->isValid()) { $contrat = $formMarkdown->getData(); $dm->persist($contrat); $dm->flush(); } $formGenerator = $this->createForm(new ContratGeneratorType(), $contrat, array('action' => $this->generateUrl('contrat_markdown', array('id' => $contrat->getId())), 'method' => 'POST')); $formGenerator->handleRequest($request); if ($formGenerator->isSubmitted() && $formGenerator->isValid()) { $contrat = $formGenerator->getData(); $contrat->setMarkdown($this->renderView('contrat/contrat.markdown.twig', array('contrat' => $contrat))); $dm->persist($contrat); $dm->flush(); } return $this->render('contrat/visualisation.markdown.twig', array('contrat' => $contrat, 'formMarkdown' => $formMarkdown->createView(), 'formGenerator' => $formGenerator->createView())); }