em = $em; $this->translatorAdmin = $translatorAdmin; $this->merchantResolver = $merchantResolver; $this->sectionResolver = $sectionResolver; $this->merchantSettingDefinition = $merchantSettingDefinition; $this->sectionSettingDefinition = $sectionSettingDefinition; $this->siteSettingDefinition = $siteSettingDefinition; $this->siteRepository = $siteRepository; } /** * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant") */ public function manageMerchant(Request $request) { return $this->manage($request, 'merchant'); } /** * @Route("/admin/setting/section", name="carac_admin_setting_section") */ public function manageSection(Request $request) { return $this->manage($request, 'section'); } public function manage(Request $request, $type) { $entity = null; if ($type == 'merchant') { $resolver = $this->merchantResolver; $formClass = MerchantSettingsFormType::class; $settingDefinition = $this->merchantSettingDefinition; } elseif ($type == 'section') { $resolver = $this->sectionResolver; $formClass = SectionSettingsFormType::class; $settingDefinition = $this->sectionSettingDefinition; } $entity = $resolver->getCurrent(); if ($entity) { $form = $this->createForm($formClass, $entity); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->em->update($entity); $this->em->flush(); $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved')); } return $this->render( '@LcCaracole/admin/setting/edit_' . $type . '.html.twig', [ 'display_switch_section' => ($type == 'section') ? true : false, 'resolver' => $resolver, 'setting_definition' => $settingDefinition, 'form' => $form->createView() ] ); } } /** * @Route("/admin/setting/site2", name="carac_admin_setting_site") */ public function manageGlobal(Request $request) { $site = $this->siteRepository->findOneByDevAlias('default'); $form = $this->createForm(SiteSettingsFormType::class, $site); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $this->em->update($site); $this->em->flush(); $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved')); } return $this->render( '@LcCaracole/admin/setting/edit_site.html.twig', [ 'setting_definition' => $this->siteSettingDefinition, 'form' => $form->createView() ] ); } }