public function putPostCommentsAction($postId, $commentId, Request $request)
    {
        $post = $this->getPost($postId);

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

        $comment = $this->commentManager->find($commentId);

        if (null === $comment) {
            throw new NotFoundHttpException(sprintf('Comment (%d) not found', $commentId));
        }

        $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();
            $this->commentManager->save($comment);

            return $comment;
        }

        return $form;
    }
public function putPostCommentsAction($postId, $commentId, Request $request)
    {
        $post = $this->getPost($postId);

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

        $comment = $this->commentManager->find($commentId);

        if (null === $comment) {
            throw new NotFoundHttpException(sprintf('Comment (%d) not found', $commentId));
        }

        $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();
            $this->commentManager->save($comment);

            return $comment;
        }

        return $form;
    }
public function putPostCommentsAction ( $ postId , $ commentId , Request $ request ) { $ post = $ this -> getPost ( $ postId ) ; if ( ! $ post -> isCommentable ( ) ) { throw new HttpException ( 403 , sprintf ( 'Post (%d) not commentable' , $ postId ) ) ; } $ comment = $ this -> commentManager -> find ( $ commentId ) ; if ( null === $ comment ) { throw new NotFoundHttpException ( sprintf ( 'Comment (%d) not found' , $ commentId ) ) ; } $ 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 ( ) ; $ this -> commentManager -> save ( $ comment ) ; return $ comment ; } return $ form ; }
Updates a comment.

@ApiDoc(
requirements={
{"name"="postId", "dataType"="integer", "requirement"="\d+", "description"="post identifier"},
{"name"="commentId", "dataType"="integer", "requirement"="\d+", "description"="comment identifier"}
},
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 update",
404="Returned when unable to find comment"
}
)

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

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

@param int     $postId    A post identifier
@param int     $commentId A comment identifier
@param Request $request   A Symfony request

@throws NotFoundHttpException
@throws HttpException

@return Comment
Updates a comment .