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

updateAction() public method

Edits an existing Section entity.
public updateAction ( Request $request, $id ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
$id
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');
        if (!$this->isGranted('EDIT', $journal, 'sections')) {
            throw new AccessDeniedException("You are not authorized for edit this journal's section!");
        }
        $em = $this->getDoctrine()->getManager();
        $entity = $em->getRepository('OjsJournalBundle:Section')->find($id);
        if (!$entity) {
            throw $this->createNotFoundException('notFound');
        }
        $editForm = $this->createEditForm($entity);
        $editForm->handleRequest($request);
        if ($editForm->isValid()) {
            $event = new JournalItemEvent($entity);
            $eventDispatcher->dispatch(SectionEvents::PRE_UPDATE, $event);
            $em->persist($event->getItem());
            $em->flush();
            $event = new JournalItemEvent($event->getItem());
            $eventDispatcher->dispatch(SectionEvents::POST_UPDATE, $event);
            if ($event->getResponse()) {
                return $event->getResponse();
            }
            $this->successFlashBag('successful.update');
            return $this->redirectToRoute('ojs_journal_section_edit', ['id' => $id, 'journalId' => $journal->getId()]);
        }
        return $this->render('OjsJournalBundle:Section:edit.html.twig', array('entity' => $entity, 'edit_form' => $editForm->createView()));
    }