|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
-
- namespace Lc\CaracoleBundle\Twig;
-
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
- use Symfony\Component\Form\FormFactoryInterface;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFunction;
-
- class FormTwigExtension extends AbstractExtension
- {
- protected FormFactoryInterface $formFactory;
- protected UrlGeneratorInterface $urlGenerator;
-
- public function __construct(
- FormFactoryInterface $formFactory,
- UrlGeneratorInterface $urlGenerator
- ) {
- $this->formFactory = $formFactory;
- $this->urlGenerator = $urlGenerator;
- }
-
- public function getFunctions()
- {
- return array(
- new TwigFunction('carac_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
- new TwigFunction('carac_form_switch_section', [$this, 'getFormSwitchSection']),
- );
- }
-
- public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch', $csrfProtection = true)
- {
- $form = $this->formFactory->create(
- SwitchMerchantFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate($actionRoute),
- 'attr' => ['class' => 'switch-merchant'],
- 'csrf_protection' => $csrfProtection,
- 'context' => $context
- ]
- );
- return $form->createView();
- }
-
- public function getFormSwitchSection()
- {
- $form = $this->formFactory->create(
- SwitchSectionFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('admin_section_switch'),
- 'attr' => ['class' => 'switch-section']
- ]
- );
- return $form->createView();
- }
- }
|