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