/** * @Secure(roles="ROLE_CMS_CONTENT,ROLE_SUPERADMIN") */ public function categoryEditAction(Request $request, $blog, $id) { $accessor = PropertyAccess::createPropertyAccessor(); $em = $this->getDoctrine()->getManager(); $session = $this->get('session'); $blog = $em->getRepository('MajesBlogBundle:Blog')->findOneById($blog); $category = $em->getRepository('MajesBlogBundle:Category')->findOneById($id); if (is_null($category)) { $category = new Category(); } $category->setLang($this->_lang); $formCategory = $this->createForm(new CategoryType($request->getSession()), $category); if (!is_null($category->getId())) { $copy = $request->get('copy'); if (is_null($category->getLang()) && $copy) { $category->setLang($this->_default_lang); $new_lang = clone $category->getLang(); $new_lang->setLocale($this->_lang); $new_lang->setUrl($new_lang->getUrl() . '-' . $this->_lang); $new_lang->setCreateDate(new \DateTime()); $category->addLang($new_lang); $em->persist($category); $em->flush(); $category->setLang($this->_lang); $formCategory = $this->createForm(new CategoryType($request->getSession()), $category); } elseif (is_null($category->getLang())) { $new_lang = new CategoryLang(); $new_lang->setLocale($this->_lang); $category->addLang($new_lang); $category->setLang($this->_lang); $formCategory = $this->createForm(new CategoryType($request->getSession()), $category); } } if ($request->getMethod() == 'POST') { $formCategory->handleRequest($request); if ($formCategory->isValid()) { if (is_null($category->getId())) { $category->setBlog($blog); $category = $formCategory->getData(); $categoryLang = $formCategory->get('lang')->getData(); $categoryLang->setLocale($this->_lang); $categoryLang->setCategory($category); $category->addLang($categoryLang); } else { $category = $formCategory->getData(); if (is_null($category->getLang()->getId())) { $category->getLang()->setArticle($category); } } $em->persist($category); $em->flush(); return $this->redirect($this->generateUrl('_blog_category_edit', array('blog' => $blog->getId(), 'id' => $category->getId()))); } } return $this->render('MajesBlogBundle:Admin:content.html.twig', array('pageTitle' => 'Blog Management', 'pageSubTitle' => 'Category Edit', 'form' => $formCategory->createView(), 'blog' => $blog, 'article' => $category->getId(), 'object' => new Category(), 'datas' => null, 'edit' => null, 'attributes' => null, 'edit_article' => null, 'edit_categ' => true, 'setup' => null, 'block' => null, 'page_has_draft' => null, 'lang' => 'fr', 'form_social' => null, 'urls' => array('add' => '_blog_article_edit'))); }