Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

63 linhas
2.2KB

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