No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

FormTwigExtension.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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($section)
  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. 'section' => $section,
  50. ]
  51. );
  52. return $form->createView();
  53. }
  54. }