|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
-
- namespace Lc\CaracoleBundle\Twig;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
- 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_merchhant', [$this, 'getFormSwitchMerchant']),
- );
- }
-
- public function getSections()
- {
- return $this->sectionRepository->findAll();
- }
-
- public function getMerchants()
- {
- return $this->merchantRepository->findAll();
- }
-
- public function getFormSwitchMerchant()
- {
- $form = $this->formFactory->create(
- SwitchMerchantFormType::class,
- null,
- [
- 'action' => $this->urlGenerator->generate('carac_switch_merchant'),
- 'attr' => ['class' => 'switch-merchant']
- ]
- );
- return $form->createView();
- }
- }
|