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