public function postPostCommentsAction($id, Request $request)
    {
        $post = $this->getPost($id);

        if (!$post->isCommentable()) {
            throw new HttpException(403, sprintf('Post (%d) not commentable', $id));
        }

        $comment = $this->commentManager->create();
        $comment->setPost($post);

        $form = $this->formFactory->createNamed(null, 'sonata_news_api_form_comment', $comment, ['csrf_protection' => false]);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $comment = $form->getData();
            $comment->setPost($post);

            if (!$comment->getStatus()) {
                $comment->setStatus($post->getCommentsDefaultStatus());
            }

            $this->commentManager->save($comment);
            $this->mailer->sendCommentNotification($comment);

            return $comment;
        }

        return $form;
    }
public function postPostCommentsAction($id, Request $request)
    {
        $post = $this->getPost($id);

        if (!$post->isCommentable()) {
            throw new HttpException(403, sprintf('Post (%d) not commentable', $id));
        }

        $comment = $this->commentManager->create();
        $comment->setPost($post);

        $form = $this->formFactory->createNamed(null, 'sonata_news_api_form_comment', $comment, ['csrf_protection' => false]);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $comment = $form->getData();
            $comment->setPost($post);

            if (!$comment->getStatus()) {
                $comment->setStatus($post->getCommentsDefaultStatus());
            }

            $this->commentManager->save($comment);
            $this->mailer->sendCommentNotification($comment);

            return $comment;
        }

        return $form;
    }
public function postPostCommentsAction ( $ id , Request $ request ) { $ post = $ this -> getPost ( $ id ) ; if ( ! $ post -> isCommentable ( ) ) { throw new HttpException ( 403 , sprintf ( 'Post (%d) not commentable' , $ id ) ) ; } $ comment = $ this -> commentManager -> create ( ) ; $ comment -> setPost ( $ post ) ; $ form = $ this -> formFactory -> createNamed ( null , 'sonata_news_api_form_comment' , $ comment , [ 'csrf_protection' => false ] ) ; $ form -> handleRequest ( $ request ) ; if ( $ form -> isValid ( ) ) { $ comment = $ form -> getData ( ) ; $ comment -> setPost ( $ post ) ; if ( ! $ comment -> getStatus ( ) ) { $ comment -> setStatus ( $ post -> getCommentsDefaultStatus ( ) ) ; } $ this -> commentManager -> save ( $ comment ) ; $ this -> mailer -> sendCommentNotification ( $ comment ) ; return $ comment ; } return $ form ; }
Adds a comment to a post.

@ApiDoc(
requirements={
{"name"="id", "dataType"="integer", "requirement"="\d+", "description"="post id"}
},
input={"class"="sonata_news_api_form_comment", "name"="", "groups"={"sonata_api_write"}},
output={"class"="Sonata\NewsBundle\Model\Comment", "groups"={"sonata_api_read"}},
statusCodes={
200="Returned when successful",
400="Returned when an error has occurred while comment creation",
403="Returned when commenting is not enabled on the related post",
404="Returned when post is not found"
}
)

@REST\View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true)

@REST\Route(requirements={"_format"="json|xml"})

@param int     $id      A post identifier
@param Request $request

@throws HttpException

@return Comment|FormInterface
Adds a comment to a post .