Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

FormTwigExtension.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  4. use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
  5. use Symfony\Component\Form\FormFactoryInterface;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Twig\Extension\AbstractExtension;
  8. use Twig\TwigFunction;
  9. class FormTwigExtension extends AbstractExtension
  10. {
  11. protected FormFactoryInterface $formFactory;
  12. protected UrlGeneratorInterface $urlGenerator;
  13. public function __construct(
  14. FormFactoryInterface $formFactory,
  15. UrlGeneratorInterface $urlGenerator
  16. ) {
  17. $this->formFactory = $formFactory;
  18. $this->urlGenerator = $urlGenerator;
  19. }
  20. public function getFunctions()
  21. {
  22. return array(
  23. new TwigFunction('carac_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
  24. new TwigFunction('carac_form_switch_section', [$this, 'getFormSwitchSection']),
  25. );
  26. }
  27. public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch', $csrfProtection = true)
  28. {
  29. $form = $this->formFactory->create(
  30. SwitchMerchantFormType::class,
  31. null,
  32. [
  33. 'action' => $this->urlGenerator->generate($actionRoute),
  34. 'attr' => ['class' => 'switch-merchant'],
  35. 'csrf_protection' => $csrfProtection,
  36. 'context' => $context
  37. ]
  38. );
  39. return $form->createView();
  40. }
  41. public function getFormSwitchSection()
  42. {
  43. $form = $this->formFactory->create(
  44. SwitchSectionFormType::class,
  45. null,
  46. [
  47. 'action' => $this->urlGenerator->generate('admin_section_switch'),
  48. 'attr' => ['class' => 'switch-section']
  49. ]
  50. );
  51. return $form->createView();
  52. }
  53. }