public function createAction(Request $request)
{
$journal = $this->get('ojs.journal_service')->getSelectedJournal();
$journalMandatoryLocale = $journal->getMandatoryLang()->getCode();
$eventDispatcher = $this->get('event_dispatcher');
if (!$this->isGranted('CREATE', $journal, 'posts')) {
throw new AccessDeniedException("You are not authorized for this post!");
}
$entity = new JournalPost();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$entity->setCurrentLocale($journalMandatoryLocale);
$entity->setJournal($journal);
$em = $this->getDoctrine()->getManager();
$entity->setSlug($entity->getTranslationByLocale($journalMandatoryLocale)->getTitle());
$event = new JournalItemEvent($entity);
$eventDispatcher->dispatch(JournalPostEvents::PRE_CREATE, $event);
$em->persist($event->getItem());
$em->flush();
$event = new JournalItemEvent($event->getItem());
$eventDispatcher->dispatch(JournalPostEvents::POST_CREATE, $event);
if ($event->getResponse()) {
return $event->getResponse();
}
$this->successFlashBag('successful.create');
return $this->redirectToRoute('ojs_journal_post_show', ['id' => $entity->getId(), 'journalId' => $journal->getId()]);
}
return $this->render('OjsJournalBundle:JournalPost:new.html.twig', ['entity' => $entity, 'form' => $form->createView()]);
}