您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SettingAdminController.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Setting;
  3. use Lc\CaracoleBundle\Controller\ControllerTrait;
  4. use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
  5. use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
  6. use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
  7. use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class SettingAdminController extends SovSettingController
  11. {
  12. use ControllerTrait;
  13. /**
  14. * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
  15. */
  16. public function manageMerchant(Request $request)
  17. {
  18. return $this->manage($request, 'merchant');
  19. }
  20. /**
  21. * @Route("/admin/setting/section", name="carac_admin_setting_section")
  22. */
  23. public function manageSection(Request $request)
  24. {
  25. return $this->manage($request, 'section');
  26. }
  27. public function manage(
  28. Request $request,
  29. $type
  30. ) {
  31. $entity = null;
  32. $entityManager = $this->getEntityManager();
  33. if ($type == 'merchant') {
  34. $resolver = $this->getMerchantContainer()->getResolver();
  35. $formClass = MerchantSettingsFormType::class;
  36. $settingDefinition = $this->getMerchantSettingContainer()->getDefinition();
  37. } elseif ($type == 'section') {
  38. $resolver = $this->getSectionContainer()->getResolver();
  39. $formClass = SectionSettingsFormType::class;
  40. $settingDefinition = $this->getSectionSettingContainer()->getDefinition();
  41. }
  42. $entity = $resolver->getCurrent();
  43. $displaySwitchSection = ($type == 'section') ? true : false;
  44. $view = '@LcCaracole/admin/setting/edit_' . $type . '.html.twig';
  45. if ($entity) {
  46. $form = $this->createForm($formClass, $entity);
  47. $form->handleRequest($request);
  48. if ($form->isSubmitted() && $form->isValid()) {
  49. $entityManager->update($entity);
  50. $entityManager->flush();
  51. $this->addFlashTranslator('success', 'updated');
  52. }
  53. return $this->render(
  54. $view,
  55. [
  56. 'display_switch_section' => $displaySwitchSection,
  57. 'resolver' => $resolver,
  58. 'setting_definition' => $settingDefinition,
  59. 'form' => $form->createView()
  60. ]
  61. );
  62. }
  63. else {
  64. return $this->render(
  65. $view,
  66. [
  67. 'display_switch_section' => $displaySwitchSection,
  68. 'replace_content_with_message' => "Vous devez sélectionner une section pour afficher ces données."
  69. ]
  70. );
  71. }
  72. }
  73. /**
  74. * @Route("/admin/setting/site2", name="carac_admin_setting_site")
  75. */
  76. public function manageGlobal(Request $request)
  77. {
  78. $entityManager = $this->getEntityManager();
  79. $site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default');
  80. $form = $this->createForm(SiteSettingsFormType::class, $site);
  81. $form->handleRequest($request);
  82. if ($form->isSubmitted() && $form->isValid()) {
  83. $entityManager->update($site);
  84. $entityManager->flush();
  85. $this->addFlashTranslator('success', 'updated');
  86. }
  87. return $this->render(
  88. '@LcCaracole/admin/setting/edit_site.html.twig',
  89. [
  90. 'setting_definition' => $this->getSiteSettingContainer()->getDefinition(),
  91. 'form' => $form->createView()
  92. ]
  93. );
  94. }
  95. }