/** * @Route("/{id}/sibling", name="cp_terms_admin_section_add_sibling", requirements={"id": "\d+"}) * @Template("CPTermsBundle:Section:new.html.twig") */ public function addSiblingAction(Request $request, $id) { $section = $this->getSection($id, true); $sibling = new Section(); $sibling->insertAsNextSiblingOf($section); $form = $this->createForm(new SectionFormType(), $sibling, array('action' => $this->generateUrl('cp_terms_admin_section_add_sibling', array('id' => $id)))); $form->handleRequest($request); if ($form->isValid()) { $sibling->save(); $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('section.add_sibling.success', array('%section%' => $section->getTitle(), '%sibling%' => $sibling->getTitle()), 'CPTermsBundle', $request->getLocale())); return $this->redirect($this->generateUrl('cp_terms_admin_show', array('id' => $section->getTermsId()))); } return array('form' => $form->createView(), 'level' => $sibling->getLevel(), 'prefix' => $request->query->get('prefix')); }
/** * @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; }