Skip to content

Commit 5c11bcd

Browse files
committed
Refactor new comment action
1 parent 3ac8164 commit 5c11bcd

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/AppBundle/Controller/BlogController.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,15 @@ public function postShowAction(Post $post)
9292
*/
9393
public function commentNewAction(Request $request, Post $post)
9494
{
95-
$form = $this->createForm(CommentType::class);
95+
$comment = new Comment();
96+
$comment->setAuthor($this->getUser());
97+
$comment->setPost($post);
98+
99+
$form = $this->createForm(CommentType::class, $comment);
96100

97101
$form->handleRequest($request);
98102

99103
if ($form->isSubmitted() && $form->isValid()) {
100-
/** @var Comment $comment */
101-
$comment = $form->getData();
102-
$comment->setAuthor($this->getUser());
103-
$comment->setPost($post);
104-
105104
$entityManager = $this->getDoctrine()->getManager();
106105
$entityManager->persist($comment);
107106
$entityManager->flush();

0 commit comments

Comments
 (0)