Created
April 30, 2011 05:30
-
-
Save merk/949452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function createAction($threadIdentifier) | |
{ | |
$thread = $this->container->get('fos_comment.manager.thread')->findThreadByIdentifier($threadIdentifier); | |
if (!$thread) { | |
throw new NotFoundHttpException(sprintf('Thread with identifier of "%s" does not exist', $threadIdentifier)); | |
} | |
if ($replyToId = $this->container->get('request')->request->get('reply_to')) { | |
$parent = $this->container->get('fos_comment.manager.comment')->findCommentById($replyToId); | |
if (!$parent) { | |
throw new NotFoundHttpException(sprintf('Parent comment with identifier "%s" does not exist', $replyToId)); | |
} | |
} else { | |
$parent = null; | |
} | |
$comment = $this->container->get('fos_comment.manager.comment')->createComment($thread, $replyTo); | |
$form = $this->container->get('fos_comment.form_factory.comment')->createForm(); | |
$form->setData($comment); | |
$request = $this->container->get('request'); | |
if ('POST' == $request->getMethod()) { | |
$form->bindRequest($request); | |
if ($form->isValid() && $this->container->get('fos_comment.creator.comment')->create($comment, $parent)) { | |
return $this->onCreateSuccess($form); | |
} | |
} | |
return $this->onCreateError($form); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment