Ejemplo n.º 1
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $articleLang = $options['data']->getLang();
     if (is_null($options['data']->getLang())) {
         $articleLang = new ArticleLang();
         $articleLang->setLocale($this->_locale);
     }
     $builder->add('enableComments', 'checkbox', array('required' => false, 'label' => 'Enable Comments'))->add('isActive', 'checkbox', array('required' => false, 'label' => 'is Active'))->add('lang', new ArticleLangType(), array('data' => $articleLang));
 }
Ejemplo n.º 2
0
 /**
  * @Secure(roles="ROLE_CMS_CONTENT,ROLE_SUPERADMIN")
  *
  */
 public function articleEditAction(Request $request, $blog, $id)
 {
     $accessor = PropertyAccess::createPropertyAccessor();
     $em = $this->getDoctrine()->getManager();
     $session = $this->get('session');
     $blog = $em->getRepository('MajesBlogBundle:Blog')->findOneById($blog);
     $articleLang = $em->getRepository('MajesBlogBundle:ArticleLang')->findOneById($id);
     $article = null;
     if (!is_null($articleLang)) {
         $article = $articleLang->getArticle();
     }
     if (is_null($article)) {
         $article = new Article();
     }
     $article->setLang($this->_lang);
     $formArticle = $this->createForm(new ArticleType($request->getSession(), $this->_lang), $article);
     $formArticleSocial = null;
     $blocks = null;
     $attributes = array();
     $block = array();
     if (!is_null($article->getId())) {
         $copy = $request->get('copy');
         if (is_null($article->getLang()) && $copy) {
             $article->setLang($this->_default_lang);
             $new_lang = clone $article->getLang();
             $new_lang->setLocale($this->_lang);
             $new_lang->setUrl($new_lang->getUrl() . '-' . $this->_lang);
             $new_lang->setCreateDate(new \DateTime());
             $article->addLang($new_lang);
             $em->persist($article);
             $em->flush();
             $article->setLang($this->_lang);
             $formArticle = $this->createForm(new ArticleType($request->getSession(), $this->_lang), $article);
         } elseif (is_null($article->getLang())) {
             $new_lang = new ArticleLang();
             $new_lang->setLocale($this->_lang);
             //$new_lang->setUrl('');
             $article->addLang($new_lang);
             // $em->persist($article);
             // $em->flush();
             $article->setLang($this->_lang);
             $formArticle = $this->createForm(new ArticleType($request->getSession(), $this->_lang), $article);
         }
         $formArticleSocial = $this->createForm(new ArticleSocialType($request->getSession()), $article->getLang(), array('action' => $this->get('router')->generate('_blog_article_social_edit', array('blog' => $blog->getId(), 'id' => $articleLang->getId()))))->createView();
         $attributesSetted = $session->get('menu')['cms']['submenu']['blog']['attributes'];
         foreach ($attributesSetted as $key => $value) {
             $attribute = $em->getRepository('MajesCmsBundle:Attribute')->findOneById($value);
             $attributes[$key] = array('attribute' => $attribute, 'value' => $accessor->getValue($article->getLang(), $key));
         }
         $block = array('title' => 'Content', 'update_date' => $article->getLang()->getContentUpdateDate(), 'attributes' => $attributes);
     }
     if ($request->getMethod() == 'POST') {
         $formArticle->handleRequest($request);
         if ($formArticle->isValid()) {
             if (is_null($article->getId())) {
                 $article->setBlog($blog);
                 $article = $formArticle->getData();
                 $articleLang = $formArticle->get('lang')->getData();
                 $articleLang->setLocale($this->_lang);
                 $articleLang->setArticle($article);
                 $article->addLang($articleLang);
             } else {
                 $article = $formArticle->getData();
                 if (is_null($article->getLang()->getId())) {
                     $article->getLang()->setArticle($article);
                 }
             }
             $em->persist($article);
             $em->flush();
             return $this->redirect($this->generateUrl('_blog_article_edit', array('blog' => $blog->getId(), 'id' => $articleLang->getId())));
         }
     }
     return $this->render('MajesBlogBundle:Admin:content.html.twig', array('pageTitle' => 'Blog Management', 'pageSubTitle' => 'Article Edit', 'form' => $formArticle->createView(), 'blog' => $blog, 'article' => $article->getId(), 'object' => new Article(), 'datas' => null, 'edit' => null, 'attributes' => $attributes, 'edit_article' => true, 'edit_categ' => null, 'setup' => null, 'block' => $block, 'page_has_draft' => null, 'lang' => 'fr', 'form_social' => $formArticleSocial, 'urls' => array('add' => '_blog_article_edit')));
 }