Ojs\JournalBundle\Controller\JournalPostController::updateAction PHP Метод

updateAction() публичный Метод

Edits an existing Lang entity.
public updateAction ( Request $request, integer $id ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
$id integer
Результат 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');
        $entity = $this->getDoctrine()->getRepository('OjsJournalBundle:JournalPost')->find($id);
        $this->throw404IfNotFound($entity);
        if (!$this->isGranted('EDIT', $journal, 'posts')) {
            throw new AccessDeniedException("You are not authorized for this post!");
        }
        $em = $this->getDoctrine()->getManager();
        $editForm = $this->createEditForm($entity);
        $editForm->handleRequest($request);
        if ($editForm->isValid()) {
            $entity->setSlug($entity->getTranslationByLocale($request->getDefaultLocale())->getTitle());
            $event = new JournalItemEvent($entity);
            $eventDispatcher->dispatch(JournalPostEvents::PRE_UPDATE, $event);
            $em->persist($event->getItem());
            $em->flush();
            $event = new JournalItemEvent($event->getItem());
            $eventDispatcher->dispatch(JournalPostEvents::POST_UPDATE, $event);
            if ($event->getResponse()) {
                return $event->getResponse();
            }
            $this->successFlashBag('successful.update');
            return $this->redirectToRoute('ojs_journal_post_edit', ['id' => $entity->getId(), 'journalId' => $journal->getId()]);
        }
        return $this->render('OjsJournalBundle:JournalPost:edit.html.twig', array('entity' => $entity, 'edit_form' => $editForm->createView()));
    }