Example #1
0
 public function editEntityAction(CMSEntity $cmsEntity, $entity, Application $app, Request $request)
 {
     $entityFormType = $cmsEntity->getFormType();
     $form = $app['form.factory']->create($entityFormType, $entity);
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $isNewEntity = $entity->getId() == null;
         $entity = $form->getData();
         $app['em']->persist($entity);
         $app['em']->flush();
         if ($isNewEntity) {
             return $app->redirect($app->url('cms_list', ['entityName' => $cmsEntity]));
         } else {
             return $app->redirect($app->url('cms_edit', ['entityName' => $cmsEntity, 'id' => $entity->getId()]));
         }
     }
     return $app->render('admin/edit.html.twig', ['form' => $form->createView(), 'heading' => ucwords($cmsEntity)]);
 }