/** * Ajax Update Tree * * @Route("/update-tree/{page}/{parent}/{prev}/{next}", name="page_update_tree", * requirements={"page" = "\d+", "parent" = "\d+", "prev" = "\d+", "next" = "\d+"}, * options={"expose"=true} * ) * @Method("PUT") * 6/0/5/0 */ public function updateTreeAction(Page $page, Page $parent = null, Page $prev = null, Page $next = null) { $em = $this->getDoctrine()->getManager(); $repo = $em->getRepository('AppBundle:Page'); $data = []; if (null === $page->getParent() or in_array($page->getTitle(), [Page::MAIN_MENU_TITLE, Page::EXTRA_MENU_TITLE])) { return new JsonResponse('Root menues are not allowed', 419); } elseif (null !== $prev) { $repo->persistAsNextSiblingOf($page, $prev); } elseif (null !== $next) { $repo->persistAsPrevSiblingOf($page, $next); } elseif (null !== $parent) { $repo->persistAsFirstChildOf($page, $parent); } else { if (null !== $parent) { return new JsonResponse('strange', 419); } $repo->persistAsFirstChildOf($page, $this->getMenuRoot()); } $repo->verify(); $em->flush(); $page = $repo->find(['id' => $page->getId()]); $data['pages'] = $this->rebuildSlugs($page, $repo, $em, true); $mainMenu = $this->get('app.main_menu')->getRoot(); $data['MainMenu'] = $this->get('knp_menu.renderer.twig')->render($mainMenu, ['style' => 'navbar']); return new JsonResponse(json_encode($data)); }
/** * Slugify the page's title. * * @param Page $page */ private function setSlug(Page $page) { $title = $page->getTitle(); $slugify = $this->getConfigurationPool()->getContainer()->get('slugify'); $page->setSlug($slugify->slugify($title)); }