Ojs\JournalBundle\Controller\JournalContactController::updateAction PHP Method

updateAction() public method

Edits an existing JournalContact entity.
public updateAction ( Request $request, integer $id ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
$id integer
return Symfony\Component\HttpFoundation\RedirectResponse | Symfony\Component\HttpFoundation\Response
    public function updateAction(Request $request, $id)
    {
        $journal = $this->get('ojs.journal_service')->getSelectedJournal();
        $eventDispatcher = $this->get('event_dispatcher');
        $em = $this->getDoctrine()->getManager();
        if (!$this->isGranted('EDIT', $journal, 'contacts')) {
            throw new AccessDeniedException("You are not authorized for view this page!");
        }
        /** @var JournalContact $entity */
        $entity = $em->getRepository('OjsJournalBundle:JournalContact')->find($id);
        $this->throw404IfNotFound($entity);
        $editForm = $this->createEditForm($entity, $journal->getId());
        $editForm->handleRequest($request);
        if ($editForm->isValid()) {
            $event = new JournalItemEvent($entity);
            $eventDispatcher->dispatch(JournalContactEvents::PRE_UPDATE, $event);
            $em->persist($event->getItem());
            $em->flush();
            $event = new JournalItemEvent($event->getItem());
            $eventDispatcher->dispatch(JournalContactEvents::POST_UPDATE, $event);
            if ($event->getResponse()) {
                return $event->getResponse();
            }
            $this->successFlashBag('successfully.update');
            return $this->redirectToRoute('ojs_journal_journal_contact_edit', array('id' => $entity->getId(), 'journalId' => $journal->getId()));
        }
        return $this->render('OjsJournalBundle:JournalContact:edit.html.twig', array('entity' => $entity, 'edit_form' => $editForm->createView()));
    }