Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TwigExtension.php 3.5KB

pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
  5. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  6. use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
  7. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
  8. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  9. use Lc\SovBundle\Translation\TranslatorAdmin;
  10. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  11. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  12. use Symfony\Component\Form\FormFactoryInterface;
  13. use Symfony\Component\HttpFoundation\RequestStack;
  14. use Symfony\Component\HttpKernel\KernelInterface;
  15. use Symfony\Component\Routing\Generator\UrlGenerator;
  16. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  17. use Symfony\Contracts\Translation\TranslatorInterface;
  18. use Twig\Extension\AbstractExtension;
  19. use Twig\TwigFunction;
  20. class TwigExtension extends AbstractExtension
  21. {
  22. protected $merchantRepository;
  23. protected $sectionRepository;
  24. protected $formFactory;
  25. protected $urlGenerator;
  26. public function __construct(
  27. MerchantRepository $merchantRepository,
  28. SectionRepository $sectionRepository,
  29. FormFactoryInterface $formFactory,
  30. UrlGeneratorInterface $urlGenerator
  31. ) {
  32. $this->merchantRepository = $merchantRepository;
  33. $this->sectionRepository = $sectionRepository;
  34. $this->formFactory = $formFactory;
  35. $this->urlGenerator = $urlGenerator;
  36. }
  37. public function getFunctions()
  38. {
  39. return array(
  40. new TwigFunction('carac_get_sections', [$this, 'getSections']),
  41. new TwigFunction('carac_get_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
  42. new TwigFunction('carac_get_form_switch_merchant_button', [$this, 'getFormSwitchMerchantButton']),
  43. new TwigFunction('carac_get_form_switch_section', [$this, 'getFormSwitchSection']),
  44. );
  45. }
  46. public function getSections()
  47. {
  48. return $this->sectionRepository->findAll();
  49. }
  50. public function getMerchants()
  51. {
  52. return $this->merchantRepository->findAll();
  53. }
  54. public function getFormSwitchMerchant($context = 'front')
  55. {
  56. $form = $this->formFactory->create(
  57. SwitchMerchantFormType::class,
  58. null,
  59. [
  60. 'action' => $this->urlGenerator->generate('carac_switch_merchant'),
  61. 'attr' => ['class' => 'switch-merchant'],
  62. 'context' => $context
  63. ]
  64. );
  65. return $form->createView();
  66. }
  67. public function getFormSwitchMerchantButton()
  68. {
  69. $form = $this->formFactory->create(
  70. SwitchMerchantButtonAdminFormType::class,
  71. null,
  72. [
  73. 'action' => $this->urlGenerator->generate('carac_switch_merchant'),
  74. ]
  75. );
  76. return $form->createView();
  77. }
  78. public function getFormSwitchSection($section)
  79. {
  80. $form = $this->formFactory->create(
  81. SwitchSectionFormType::class,
  82. null,
  83. [
  84. 'action' => $this->urlGenerator->generate('carac_switch_section'),
  85. 'attr' => ['class' => 'switch-section'],
  86. 'section' => $section,
  87. ]
  88. );
  89. return $form->createView();
  90. }
  91. }