You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.1KB

  1. <?php
  2. namespace Lc\SovBundle\Controller\Setting;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\SovBundle\Definition\SiteSettingDefinitionInterface;
  5. use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
  6. use Lc\SovBundle\Repository\Setting\SiteSettingRepositoryInterface;
  7. use Lc\SovBundle\Repository\Site\SiteRepositoryInterface;
  8. use Lc\SovBundle\Translation\TranslatorAdmin;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class SettingAdminController extends AbstractController
  13. {
  14. protected $em;
  15. protected $translatorAdmin;
  16. protected $siteSettingRepository;
  17. protected $siteSettingDefinition;
  18. protected $siteRepository;
  19. public function __construct(
  20. EntityManagerInterface $em,
  21. TranslatorAdmin $translatorAdmin,
  22. SiteSettingRepositoryInterface $siteSettingRepository,
  23. SiteSettingDefinitionInterface $siteSettingDefinition,
  24. SiteRepositoryInterface $siteRepository
  25. ) {
  26. $this->em = $em;
  27. $this->translatorAdmin = $translatorAdmin;
  28. $this->siteSettingRepository = $siteSettingRepository;
  29. $this->siteSettingDefinition = $siteSettingDefinition;
  30. $this->siteRepository = $siteRepository;
  31. }
  32. /**
  33. * @Route("/admin/setting/site", name="sov_admin_setting_global")
  34. */
  35. public function manageGlobal(Request $request)
  36. {
  37. $site = $this->siteRepository->findOneByDevAlias('default') ;
  38. $form = $this->createForm(SiteSettingsFormType::class, $site);
  39. $form->handleRequest($request);
  40. if ($form->isSubmitted() && $form->isValid()) {
  41. $this->em->update($site);
  42. $this->em->flush();
  43. $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
  44. }
  45. return $this->render(
  46. '@LcSov/admin/setting/edit_site.html.twig' ,
  47. [
  48. 'setting_definition' => $this->siteSettingDefinition,
  49. 'form' => $form->createView()
  50. ]
  51. );
  52. }
  53. }