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

publishAction() public method

public publishAction ( 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 publishAction(Request $request, $id = null)
    {
        $id = $request->get($this->admin->getIdParameter());
        $object = $this->admin->getObject($id);
        if (!$object) {
            throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
        }
        if (false === $this->admin->isGranted('PUBLISH', $object)) {
            throw new AccessDeniedException();
        }
        $this->admin->setSubject($object);
        $form = $this->admin->getForm();
        $object->setStatus(PageInterface::STATUS_PUBLISHED);
        // persist if the form was valid and if in preview mode the preview was approved
        $this->admin->update($object);
        if ($object->getStatus() == PageInterface::STATUS_PUBLISHED) {
            $this->makeSnapshot($object);
        }
        if ($this->isXmlHttpRequest()) {
            $view = $form->createView();
            // set the theme for the current Admin Form
            $this->get('twig')->getExtension('form')->renderer->setTheme($view, $this->admin->getFormTheme());
            $pageSettingsTemplate = $this->render($this->admin->getTemplate('edit'), array('action' => 'edit', 'form' => $view, 'object' => $object));
            return $this->renderJson(array('result' => 'ok', 'objectId' => $this->admin->getNormalizedIdentifier($object), 'title' => $object->__toString(), 'pageStatus' => $this->admin->trans($object->getStatus()), 'pageSettings' => $pageSettingsTemplate));
        }
        $request->getSession()->getFlashBag()->add('sonata_flash_success', $this->admin->trans('flash_publish_success'));
        return $this->redirect($this->admin->generateObjectUrl('edit', $object));
    }