/** * @Route("/create", name="cp_terms_admin_create") * @Template("CPTermsBundle:Admin:create.html.twig") */ public function createAction(Request $request) { $term = new Terms(); $form = $this->createForm(new TermsFormType(), $term, array('action' => $this->generateUrl('cp_terms_admin_create'))); $form->handleRequest($request); if ($form->isValid()) { $tos_section = new Section(); $tos_section->makeRoot(); $tos_section->setTitle($this->container->get('translator')->trans('terms.section.root.title', array(), 'CPTermsBundle', $request->getLocale())); $term->addSection($tos_section); $term->save(); return $this->redirect($this->generateUrl('cp_terms_admin_show', array('id' => $term->getId()))); } return array('form' => $form->createView()); }
public function getClone(Terms $terms, Section $parent = null) { $clone = new Section(); $clone->setTerms($terms); $clone->setTitle($this->getTitle()); $clone->setContent($this->getContent()); if ($this->isRoot()) { $clone->makeRoot(); } else { $clone->insertAsLastChildOf($parent); } $clone->save(); if (!$this->isLeaf()) { $children = $this->getChildren(); foreach ($children as $child) { $child->getClone($terms, $clone); } } return $clone; }