예제 #1
0
 /**
  * Displays a form to edit an existing Section entity or create a new one.
  *
  * @param integer $id      The id of the Section to edit
  * @param Request $request
  *
  * @return RedirectResponse|Response
  */
 public function editAction($id, Request $request)
 {
     $entity = $this->sectionRepository->find($id);
     if (false == $entity) {
         $entity = $this->initEntity(new Section());
         $entity->setApp($this->getApp());
     }
     $this->pushNavigationElement($entity);
     $form = $this->createForm(new RootSectionType(), $entity, array('current_section' => $entity, 'managed_app' => $this->getApp()));
     if ('POST' == $request->getMethod()) {
         $form->submit($request);
         if ($form->isValid()) {
             $this->getEm()->persist($entity);
             // On insert
             if (false == $id) {
                 $sectionModuleBar = $this->navigationRepository->find(NavigationRepository::SECTION_MODULE_BAR_ID);
                 $backendApp = $this->appRepository->find(1);
                 $mapping = new Mapping();
                 $mapping->setSection($entity);
                 $mapping->setApp($backendApp);
                 $mapping->setType('route');
                 $mapping->setTarget('unifik_system_backend_text');
                 $entity->addMapping($mapping);
                 $mapping = new Mapping();
                 $mapping->setSection($entity);
                 $mapping->setApp($backendApp);
                 $mapping->setNavigation($sectionModuleBar);
                 $mapping->setType('render');
                 $mapping->setTarget('UnifikSystemBundle:Backend/Text/Navigation:SectionModuleBar');
                 $entity->addMapping($mapping);
                 $mapping = new Mapping();
                 $mapping->setSection($entity);
                 $mapping->setApp($backendApp);
                 $mapping->setNavigation($sectionModuleBar);
                 $mapping->setType('render');
                 $mapping->setTarget('UnifikSystemBundle:Backend/Section/Navigation:SectionModuleBar');
                 $entity->addMapping($mapping);
                 // Frontend mapping
                 $mapping = new Mapping();
                 $mapping->setSection($entity);
                 $mapping->setApp($this->getApp());
                 $mapping->setType('route');
                 $mapping->setTarget('unifik_system_frontend_text');
                 $entity->addMapping($mapping);
             }
             $this->getEm()->flush();
             $this->get('unifik_system.router_invalidator')->invalidate();
             $this->addFlashSuccess($this->get('translator')->trans('%entity% has been saved.', array('%entity%' => $entity)));
             if ($request->request->has('save')) {
                 return $this->redirect($this->generateUrl('unifik_system_backend_section_root', array('appSlug' => $this->getApp()->getSlug())));
             }
             return $this->redirect($this->generateUrl('unifik_system_backend_section_root_edit', array('id' => $entity->getId() ?: 0, 'appSlug' => $this->getApp()->getSlug())));
         } else {
             $this->addFlashError('Some fields are invalid.');
         }
     }
     return $this->render('UnifikSystemBundle:Backend/Section/Root:edit.html.twig', array('entity' => $entity, 'form' => $form->createView(), 'managedApp' => $this->getApp()));
 }
 /**
  * Deletes a App entity.
  *
  * @param Request $request
  * @param integer $applicationId
  *
  * @return RedirectResponse
  */
 public function deleteAction(Request $request, $applicationId)
 {
     $application = $this->appRepository->find($applicationId);
     $this->deleteEntity($application);
     $this->get('unifik_system.router_invalidator')->invalidate();
     return $this->redirect($this->generateUrl('unifik_system_backend_application'));
 }