|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
-
- namespace Lc\CaracoleBundle\Twig;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
- use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Liip\ImagineBundle\Imagine\Cache\CacheManager;
- use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
- use Symfony\Component\Form\FormFactoryInterface;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpKernel\KernelInterface;
- use Symfony\Component\Routing\Generator\UrlGenerator;
- use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFunction;
-
- class TwigExtension extends AbstractExtension
- {
- protected $merchantRepository;
- protected $sectionRepository;
- protected $formFactory;
- protected $urlGenerator;
-
- public function __construct(
- MerchantRepository $merchantRepository,
- SectionRepository $sectionRepository,
- FormFactoryInterface $formFactory,
- UrlGeneratorInterface $urlGenerator
- ) {
- $this->merchantRepository = $merchantRepository;
- $this->sectionRepository = $sectionRepository;
- $this->formFactory = $formFactory;
- $this->urlGenerator = $urlGenerator;
- }
-
- public function getFunctions()
- {
- return array(
- new TwigFunction('carac_get_sections', [$this, 'getSections']),
- new TwigFunction('carac_get_form_switch_merchant', [$this, 'getFormSwitchMerchant']),
- new TwigFunction('carac_get_form_switch_merchant_button', [$this, 'getFormSwitchMerchantButton']),
- new TwigFunction('carac_get_form_switch_section', [$this, 'getFormSwitchSection']),
- );
- }
-
- public function getSections()
- {
- return $this->sectionRepository->findAll();
- }
-
- public function getMerchants()
- {
- return $this->merchantRepository->findAll();
- }
-
- public function getFormSwitchMerchant($context = 'front')
- {
- $form = $this->formFactory->create(
- SwitchMerchantFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('carac_switch_merchant'),
- 'attr' => ['class' => 'switch-merchant'],
- 'context' => $context
- ]
- );
- return $form->createView();
- }
-
- public function getFormSwitchMerchantButton()
- {
- $form = $this->formFactory->create(
- SwitchMerchantButtonAdminFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('carac_switch_merchant'),
- ]
- );
- return $form->createView();
- }
-
- public function getFormSwitchSection($section)
- {
- $form = $this->formFactory->create(
- SwitchSectionFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('carac_switch_section'),
- 'attr' => ['class' => 'switch-section'],
- 'section' => $section,
- ]
- );
- return $form->createView();
- }
- }
|