public function loadFrontend(ObjectManager $manager) { $mapping = new Mapping(); $mapping->setTarget('unifik_system_frontend_home'); $mapping->setType('route'); $mapping->setSection($manager->merge($this->getReference('section-home'))); $mapping->setApp($manager->merge($this->getReference('app-frontend'))); $manager->persist($mapping); $manager->flush(); }
/** * Displays a form to edit an existing Text entity. * * @param Request $request * @param integer $id The Section ID * * @return RedirectResponse|Response */ public function editAction(Request $request, $id) { $section = $this->getSection(); $app = $this->getApp(); $entity = $this->sectionRepository->find($id); if (!$entity) { $entity = $this->initEntity(new Section()); $entity->setParent($section); $entity->setApp($app); } $this->getCore()->addNavigationElement($entity); $form = $this->createForm(new SectionType(), $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); $app = $this->getEm()->getRepository('UnifikSystemBundle:App')->findOneByName('backend'); $mapping = new Mapping(); $mapping->setSection($entity); $mapping->setApp($app); $mapping->setType('route'); $mapping->setTarget('unifik_system_backend_text'); $entity->addMapping($mapping); $mapping = new Mapping(); $mapping->setSection($entity); $mapping->setApp($app); $mapping->setNavigation($sectionModuleBar); $mapping->setType('render'); $mapping->setTarget('UnifikSystemBundle:Backend/Text/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->get('save')) { return $this->redirect($this->generateUrl('unifik_system_backend_section')); } return $this->redirect($this->generateUrl('unifik_system_backend_section_edit', array('id' => $entity->getId() ?: 0))); } else { $this->addFlashError('Some fields are invalid.'); } } return $this->render('UnifikSystemBundle:Backend/Section/Section:edit.html.twig', array('entity' => $entity, 'form' => $form->createView())); }