/**
  * @Route("/create", name="forum_thread_create")
  * @ParamConverter("forum", class="StreamPerkForumBundle:Forum", options={"mapping": {"forumSlug": "slug"}})
  * @Security("is_granted('SHOW', forum)")
  */
 public function createAction(Request $request, Forum $forum)
 {
     if ($forum->getChildren()->count() > 0) {
         throw $this->createAccessDeniedException(self::CANNOT_CREATE_THREAD_MSG);
     }
     $threadManager = $this->get('streamperk.forum_thread_manager');
     $postManager = $this->get('streamperk.forum_thread_post_manager');
     $thread = $threadManager->createManagedEntity()->setForum($forum);
     $post = $postManager->createManagedEntity()->setThread($thread)->setCreator($this->getUser())->setDateCreated(new DateTime());
     $thread->addPost($post);
     if ($this->isGranted(AbstractVoter::CREATE, $thread) !== true) {
         throw $this->createAccessDeniedException(self::CANNOT_CREATE_THREAD_MSG);
     }
     if ($this->isGranted(AbstractVoter::CREATE, $post) !== true) {
         throw $this->createAccessDeniedException(self::CANNOT_CREATE_POST_MSG);
     }
     $form = $this->createForm(ForumThreadType::class, $thread);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $threadManager->persistAndFlush($thread);
         $postManager->persistAndFlush($post);
         return $this->redirectToRoute('forum_thread_index', ['forumSlug' => $forum->getSlug(), 'slug' => $thread->getSlug()]);
     }
     return $this->render('StreamPerkForumBundle:User:ForumThread/create.html.twig', ['forum' => $forum, 'form' => $form->createView()] + $this->getDefaultViewParameters());
 }