|
- <?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\UrlGeneratorInterface;
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Extension\AbstractExtension;
- use Twig\TwigFunction;
-
- class TwigExtension extends AbstractExtension
- {
- protected $em;
- protected $kernel;
- protected $parameterBag;
- protected $cacheManager;
- protected $requestStack;
- protected $router;
- protected $translator;
- protected $translatorAdmin;
- protected $merchantRepository;
- protected $sectionRepository;
- protected $formFactory;
-
- public function __construct(
- KernelInterface $kernel,
- ParameterBagInterface $parameterBag,
- CacheManager $cacheManager,
- EntityManagerInterface $entityManager,
- RequestStack $requestStack,
- UrlGeneratorInterface $router,
- TranslatorInterface $translator,
- TranslatorAdmin $translatorAdmin,
- MerchantRepository $merchantRepository,
- SectionRepository $sectionRepository,
- FormFactoryInterface $formFactory
- ) {
- $this->kernel = $kernel;
- $this->parameterBag = $parameterBag;
- $this->cacheManager = $cacheManager;
- $this->em = $entityManager;
- $this->requestStack = $requestStack;
- $this->router = $router;
- $this->translator = $translator;
- $this->translatorAdmin = $translatorAdmin;
- $this->merchantRepository = $merchantRepository;
- $this->sectionRepository = $sectionRepository;
- $this->formFactory = $formFactory;
- }
-
- 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' => '#']);
- return $form->createView();
- }
- }
|