protected function changePageStatus($id, $status) { $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('EDIT', $object)) { throw new AccessDeniedException(); } $this->admin->setSubject($object); $form = $this->admin->getForm(); $object->setStatus($status); // persist if the form was valid and if in preview mode the preview was approved $this->admin->update($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)); } $this->get('session')->getFlashBag()->add('sonata_flash_success', $this->admin->trans('flash_status_success')); return $this->redirect($this->admin->generateObjectUrl('edit', $object)); }