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