No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

84 líneas
2.8KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  5. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
  6. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  7. use Lc\SovBundle\Translation\TranslatorAdmin;
  8. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  9. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  10. use Symfony\Component\Form\FormFactoryInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpKernel\KernelInterface;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. use Twig\Extension\AbstractExtension;
  16. use Twig\TwigFunction;
  17. class TwigExtension extends AbstractExtension
  18. {
  19. protected $em;
  20. protected $kernel;
  21. protected $parameterBag;
  22. protected $cacheManager;
  23. protected $requestStack;
  24. protected $router;
  25. protected $translator;
  26. protected $translatorAdmin;
  27. protected $merchantRepository;
  28. protected $sectionRepository;
  29. protected $formFactory;
  30. public function __construct(
  31. KernelInterface $kernel,
  32. ParameterBagInterface $parameterBag,
  33. CacheManager $cacheManager,
  34. EntityManagerInterface $entityManager,
  35. RequestStack $requestStack,
  36. UrlGeneratorInterface $router,
  37. TranslatorInterface $translator,
  38. TranslatorAdmin $translatorAdmin,
  39. MerchantRepository $merchantRepository,
  40. SectionRepository $sectionRepository,
  41. FormFactoryInterface $formFactory
  42. ) {
  43. $this->kernel = $kernel;
  44. $this->parameterBag = $parameterBag;
  45. $this->cacheManager = $cacheManager;
  46. $this->em = $entityManager;
  47. $this->requestStack = $requestStack;
  48. $this->router = $router;
  49. $this->translator = $translator;
  50. $this->translatorAdmin = $translatorAdmin;
  51. $this->merchantRepository = $merchantRepository;
  52. $this->sectionRepository = $sectionRepository;
  53. $this->formFactory = $formFactory;
  54. }
  55. public function getFunctions()
  56. {
  57. return array(
  58. new TwigFunction('carac_get_sections', [$this, 'getSections']),
  59. new TwigFunction('carac_get_form_switch_merchhant', [$this, 'getFormSwitchMerchant']),
  60. );
  61. }
  62. public function getSections()
  63. {
  64. return $this->sectionRepository->findAll();
  65. }
  66. public function getMerchants()
  67. {
  68. return $this->merchantRepository->findAll();
  69. }
  70. public function getFormSwitchMerchant()
  71. {
  72. $form = $this->formFactory->create(SwitchMerchantFormType::class, null, ['action' => '#']);
  73. return $form->createView();
  74. }
  75. }