public function FormTypeEvent(FormTypeEvent $event) { $entity = $event->getEntity(); if ($entity instanceof HomePage) { $event->setFormType(new HomePageType()); } if ($entity instanceof User) { $event->setFormType(new UserType()); } if ($entity instanceof Contacts) { $event->setFormType(new ContactsType()); } if ($entity instanceof LandingPage) { $event->setFormType(new LandingPageType()); } if ($entity instanceof Page) { $event->setFormType(new PageType()); } if ($entity instanceof NavigationLink) { $event->setFormType(new NavigationLinkType()); } if ($entity instanceof NavigationMenu) { $event->setFormType(new NavigationMenuType()); } }
/** * @Route("/admin/{{editEntity}}") */ public function editEntityPageAction(Request $request, $entity, $id) { $eventDispatcher = $this->get('event_dispatcher'); $event = new EntityAndSettingsEvent(); $eventDispatcher->dispatch('custom.event.add_entity_and_settings_event', $event); $fullClass = $event->getSingleEntitySetting($entity)['fullClass']; $getEntityAndSettings = $event->getEntityAndSettings(); $fullEntityClass = new $fullClass(); $fullClassString = "{$fullClass}"; $eventDispatcher = $this->get('event_dispatcher'); $event = new FormTypeEvent(); $event->setEntity($fullEntityClass); $eventDispatcher->dispatch('custom.event.form_type_event', $event); $formType = $event->getFormType(); if ($id !== NULL) { $em = $this->getDoctrine()->getManager(); $singleResult = $em->getRepository($fullClassString)->find($id); $form = $this->createForm($formType, $singleResult); } else { $form = $this->createForm($formType, $fullEntityClass); } $form->handleRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); if ($id == NULL) { $em->persist($fullEntityClass); } $em->flush(); return $this->redirect("/admin/{$entity}"); } $classLinkTitle = ""; foreach ($getEntityAndSettings as $entitySetting) { if ($fullClassString == $entitySetting['fullClass']) { $classLinkTitle = $entitySetting['title']; } } return $this->render('AdamAdminBundle::addentity.html.twig', array('classLinkTitle' => $classLinkTitle, 'allTables' => $getEntityAndSettings, 'form' => $form->createView())); }