public function editAction($id = null)
{
/** @var Request $request */
$request = $this->container->get('request_stack')->getCurrentRequest();
// the key used to lookup the template
$templateKey = 'edit';
if ($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('EDIT', $object)) {
throw new AccessDeniedException();
}
$this->admin->setSubject($object);
/** @var $form \Symfony\Component\Form\Form */
$form = $this->admin->getForm();
$form->setData($object);
if ($request->getMethod() == 'POST') {
if (!$this->isXmlHttpRequest()) {
throw new NotFoundHttpException('Should only submit over ajax');
}
$request->attributes->add(array('objectId' => $id));
$request->attributes->add(array('page_locale' => $object->getLocale()));
$form->submit($request);
if ($form->isValid()) {
$object->setStatus(PageInterface::STATUS_DRAFT);
$this->admin->update($object);
return $this->getAjaxEditResponse($form, $object);
} else {
$form->addError(new FormError($this->admin->trans('flash_edit_error', array(), 'NetworkingInitCmsBundle')));
}
}
$view = $form->createView();
// set the theme for the current Admin Form
$this->get('twig')->getExtension('form')->renderer->setTheme($view, $this->admin->getFormTheme());
$rootMenus = $this->admin->getModelManager()->findBy('NetworkingInitCmsBundle:MenuItem', array('isRoot' => 1, 'locale' => $object->getLocale()));
return $this->render($this->admin->getTemplate($templateKey), array('action' => 'edit', 'form' => $view, 'object' => $object, 'rootMenus' => $rootMenus, 'language' => \Locale::getDisplayLanguage($object->getLocale())));
}