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.

60 line
1.9KB

  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\SiteSettingRepository;
  7. use Lc\SovBundle\Repository\Site\SiteRepository;
  8. use Lc\SovBundle\Translation\TranslatorAdmin;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class SettingAdminController extends AbstractController
  12. {
  13. protected $em;
  14. protected $translatorAdmin;
  15. protected $siteSettingRepository;
  16. protected $siteSettingDefinition;
  17. protected $siteRepository;
  18. public function __construct(
  19. EntityManagerInterface $em,
  20. TranslatorAdmin $translatorAdmin,
  21. SiteSettingRepository $siteSettingRepository,
  22. SiteSettingDefinitionInterface $siteSettingDefinition,
  23. SiteRepository $siteRepository
  24. ) {
  25. $this->em = $em;
  26. $this->translatorAdmin = $translatorAdmin;
  27. $this->siteSettingRepository = $siteSettingRepository;
  28. $this->siteSettingDefinition = $siteSettingDefinition;
  29. $this->siteRepository = $siteRepository;
  30. }
  31. public function manageGlobal(Request $request)
  32. {
  33. $site = $this->siteRepository->findOneByDevAlias('default') ;
  34. $form = $this->createForm(SiteSettingsFormType::class, $site);
  35. $form->handleRequest($request);
  36. if ($form->isSubmitted() && $form->isValid()) {
  37. $this->em->update($site);
  38. $this->em->flush();
  39. $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
  40. }
  41. return $this->render(
  42. '@LcSov/admin/setting/global.html.twig' ,
  43. [
  44. 'setting_definition' => $this->siteSettingDefinition,
  45. 'form' => $form->createView()
  46. ]
  47. );
  48. }
  49. }