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