Bundle/BlogBundle/Controller/ArticleController.php
public function newPostAction(Request $request, Blog $blog)
    {
        $article = new Article();
        $article->setBlog($blog);
        $form = $this->createForm(ArticleType::class, $article);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $page = $this->get('victoire_blog.manager.article')->create(
                $article,
                $this->getUser()
            );

            $dispatcher = $this->get('event_dispatcher');
            $event = new ArticleEvent($article);
            $dispatcher->dispatch(VictoireBlogEvents::CREATE_ARTICLE, $event);

            if (null === $response = $event->getResponse()) {
                $response = new JsonResponse([
                    'success' => true,
                    'url'     => $this->generateUrl('victoire_core_page_show', [
                        '_locale' => $request->getLocale(),
                        'url'     => $page->getUrl(),
                    ]),
                ]);
            }

            return $response;
        }

        return new JsonResponse([
            'success' => false,
            'message' => $this->container->get('victoire_form.error_helper')->getRecursiveReadableErrors($form),
            'html'    => $this->container->get('templating')->render(
                'VictoireBlogBundle:Article:new.html.twig',
                [
                    'form'   => $form->createView(),
                    'blogId' => $blog->getId(),
                ]
            ),
        ]);
    }
public function newPostAction(Request $request, Blog $blog)
    {
        $article = new Article();
        $article->setBlog($blog);
        $form = $this->createForm(ArticleType::class, $article);

        $form->handleRequest($request);
        if ($form->isValid()) {
            $page = $this->get('victoire_blog.manager.article')->create(
                $article,
                $this->getUser()
            );

            $dispatcher = $this->get('event_dispatcher');
            $event = new ArticleEvent($article);
            $dispatcher->dispatch(VictoireBlogEvents::CREATE_ARTICLE, $event);

            if (null === $response = $event->getResponse()) {
                $response = new JsonResponse([
                    'success' => true,
                    'url'     => $this->generateUrl('victoire_core_page_show', [
                        '_locale' => $request->getLocale(),
                        'url'     => $page->getUrl(),
                    ]),
                ]);
            }

            return $response;
        }

        return new JsonResponse([
            'success' => false,
            'message' => $this->container->get('victoire_form.error_helper')->getRecursiveReadableErrors($form),
            'html'    => $this->container->get('templating')->render(
                'VictoireBlogBundle:Article:new.html.twig',
                [
                    'form'   => $form->createView(),
                    'blogId' => $blog->getId(),
                ]
            ),
        ]);
    }
public function newPostAction ( Request $ request , Blog $ blog ) { $ article = new Article ( ) ; $ article -> setBlog ( $ blog ) ; $ form = $ this -> createForm ( ArticleType :: class , $ article ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ page = $ this -> get ( 'victoire_blog.manager.article' ) -> create ( $ article , $ this -> getUser ( ) ) ; $ dispatcher = $ this -> get ( 'event_dispatcher' ) ; $ event = new ArticleEvent ( $ article ) ; $ dispatcher -> dispatch ( VictoireBlogEvents :: CREATE_ARTICLE , $ event ) ; if ( null === $ response = $ event -> getResponse ( ) ) { $ response = new JsonResponse ( [ 'success' => true , 'url' => $ this -> generateUrl ( 'victoire_core_page_show' , [ '_locale' => $ request -> getLocale ( ) , 'url' => $ page -> getUrl ( ) , ] ) , ] ) ; } return $ response ; } return new JsonResponse ( [ 'success' => false , 'message' => $ this -> container -> get ( 'victoire_form.error_helper' ) -> getRecursiveReadableErrors ( $ form ) , 'html' => $ this -> container -> get ( 'templating' ) -> render ( 'VictoireBlogBundle:Article:new.html.twig' , [ 'form' => $ form -> createView ( ) , 'blogId' => $ blog -> getId ( ) , ] ) , ] ) ; }
Create a new Blog Article.

@Route("/new/{id}", name="victoire_blog_article_new_post")
@Method("POST")
@ParamConverter("blog", class="VictoireBlogBundle:Blog")

@return JsonResponse
Create a new Blog Article .