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.

65 lines
2.2KB

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