|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
-
- namespace Lc\CaracoleBundle\Twig;
-
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
- use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
- 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')
- {
- $form = $this->formFactory->create(
- SwitchMerchantFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate($actionRoute),
- 'attr' => ['class' => 'switch-merchant'],
- 'context' => $context
- ]
- );
- return $form->createView();
- }
-
- public function getFormSwitchSection($section)
- {
- $form = $this->formFactory->create(
- SwitchSectionFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('admin_section_switch'),
- 'attr' => ['class' => 'switch-section'],
- 'section' => $section,
- ]
- );
- return $form->createView();
- }
- }
|