Networking\InitCmsBundle\Controller\PageAdminController::cancelDraftAction PHP Method

cancelDraftAction() public method

public cancelDraftAction ( Request $request, null $id = null ) : RedirectResponse | Response
$request Symfony\Component\HttpFoundation\Request
$id null
return Symfony\Component\HttpFoundation\RedirectResponse | Symfony\Component\HttpFoundation\Response
    public function cancelDraftAction(Request $request, $id = null)
    {
        /** @var $draftPage PageInterface */
        $draftPage = $this->admin->getObject($id);
        if (!$draftPage) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        if (false === $this->admin->isGranted('EDIT', $draftPage)) {
            throw new AccessDeniedException();
        }
        if ($request->getMethod() == 'POST') {
            $pageManager = $this->get('networking_init_cms.page_manager');
            $serializer = $this->get('serializer');
            $publishedPage = $pageManager->revertToPublished($draftPage, $serializer);
            if ($request->isXmlHttpRequest()) {
                $form = $this->admin->getForm();
                $form->setData($publishedPage);
                $pageSettingsTemplate = $this->render($this->admin->getTemplate('edit'), array('action' => 'edit', 'form' => $form->createView(), 'object' => $publishedPage));
                return $this->renderJson(array('result' => 'ok', 'objectId' => $this->admin->getNormalizedIdentifier($publishedPage), 'title' => $publishedPage->__toString(), 'pageStatus' => $this->admin->trans($publishedPage->getStatus()), 'pageSettings' => $pageSettingsTemplate->getContent()));
            }
            return $this->redirect($this->admin->generateObjectUrl('edit', $publishedPage));
        }
        return $this->render('NetworkingInitCmsBundle:PageAdmin:page_cancel_draft.html.twig', array('action' => 'cancelDraft', 'page' => $draftPage, 'admin' => $this->admin));
    }