Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

88 lines
2.9KB

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