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