|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?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_section', [$this, 'getFormSwitchSection']),
- );
- }
-
- public function getSections()
- {
- return $this->sectionRepository->findAll();
- }
-
- public function getMerchants()
- {
- return $this->merchantRepository->findAll();
- }
-
- public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_switch_merchant')
- {
- $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('carac_switch_section'),
- 'attr' => ['class' => 'switch-section'],
- 'section' => $section,
- ]
- );
- return $form->createView();
- }
- }
|