src/Extensions/Twig/FormsExtension.php line 392

Open in your IDE?
  1. <?php
  2. namespace App\Extensions\Twig;
  3. use App\Data\SearchchambresData;
  4. use App\Data\SearchrestaurantData;
  5. use App\Entity\Agencesvoyages\Mediasagencesvoyages;
  6. use App\Entity\Contacts\Contacts;
  7. use App\Entity\Contacts\Newsletters;
  8. use App\Entity\Demandestages;
  9. use App\Entity\Hotels\Mediaannonceshotels;
  10. use App\Entity\Hotels\Mediashotels;
  11. use App\Entity\Articles\Mediaarticles;
  12. use App\Entity\Pages\Mediapages;
  13. use App\Entity\Posts\Mediaposts;
  14. use App\Entity\Actualites\Mediasactualites;
  15. use App\Entity\Salons\Mediasalons;
  16. use App\Entity\Mediaseminaires;
  17. use App\Entity\Restaurants\Mediasrestaurants;
  18. use App\Entity\Symboles\Mediassymboles;
  19. use App\Form\Agencesvoyages\MediasagencesvoyagesType;
  20. use App\Form\Contacts\ContactsType;
  21. use App\Form\Contacts\NewslettersType;
  22. use App\Form\DemandestagesType;
  23. use App\Form\Hotels\MediaannonceshotelsType;
  24. use App\Form\Hotels\MediashotelsType;
  25. use App\Form\Hotels\SearchFormChambresType;
  26. use App\Form\Articles\MediaarticlesType;
  27. use App\Form\Pages\MediapagesType;
  28. use App\Form\Posts\MediapostsType;
  29. use App\Form\Actualites\MediasactualitesType;
  30. use App\Form\Salons\MediasalonsType;
  31. use App\Form\MediaseminairesType;
  32. use App\Form\Restaurants\MediasrestaurantsType;
  33. use App\Form\Symboles\MediassymbolesType;
  34. use Psr\Container\ContainerInterface;
  35. use Symfony\Component\HttpFoundation\RequestStack;
  36. use Symfony\Contracts\Cache\CacheInterface;
  37. use Twig\Environment;
  38. use Twig\Error\LoaderError;
  39. use Twig\Error\RuntimeError;
  40. use Twig\Error\SyntaxError;
  41. use Twig\Extension\AbstractExtension;
  42. use Twig\TwigFunction;
  43. class FormsExtension extends AbstractExtension
  44. {
  45.     /**
  46.      * @var Environment
  47.      */
  48.     private $twig;
  49.     /**
  50.      * @var CacheInterface
  51.      */
  52.     private $cache;
  53.     /**
  54.      * @var ContainerInterface
  55.      */
  56.     private $container;
  57.     /**
  58.      * @var RequestStack
  59.      */
  60.     private $requestStack;
  61.     public function __construct(
  62.         Environment $twig,
  63.         CacheInterface $cache,
  64.         RequestStack $requestStack,
  65.         ContainerInterface $container
  66.     )
  67.     {
  68.         $this->twig $twig;
  69.         $this->cache $cache;
  70.         $this->container $container;
  71.         $this->requestStack $requestStack->getCurrentRequest();
  72.     }
  73.     public function getFunctions(): array
  74.     {
  75.         return [
  76.             new TwigFunction('contact_form', [$this'getContactForm'], ['is_safe' => ['html']]),
  77.             new TwigFunction('newsletter_form', [$this'getNewsletterForm'], ['is_safe' => ['html']]),
  78.             new TwigFunction('search_form', [$this'getSearchForm'], ['is_safe' => ['html']]),
  79.             new TwigFunction('search_form_restaurant', [$this'getSearchFormRestaurant'], ['is_safe' => ['html']]),
  80.             new TwigFunction('demande_stage_form', [$this'getDemandeStageForm'], ['is_safe' => ['html']]),
  81.             new TwigFunction('medias_form', [$this'getMediasForm'], ['is_safe' => ['html']]),
  82.             new TwigFunction('medias_form_symbole', [$this'getMediasFormSymbole'], ['is_safe' => ['html']]),
  83.             new TwigFunction('medias_form_agence', [$this'getMediasFormAgence'], ['is_safe' => ['html']]),
  84.             new TwigFunction('mediasseminaireimages_form', [$this'getMediasseminaireimageForm'], ['is_safe' => ['html']]),
  85.             new TwigFunction('mediassalon_form', [$this'getMediassalonForm'], ['is_safe' => ['html']]),
  86.             new TwigFunction('mediaspost_form', [$this'getMediaspostForm'], ['is_safe' => ['html']]),
  87.             new TwigFunction('mediasarticle_form', [$this'getMediasarticleForm'], ['is_safe' => ['html']]),
  88.             new TwigFunction('mediaspage_form', [$this'getMediaspageForm'], ['is_safe' => ['html']]),
  89.             new TwigFunction('mediashotels_form', [$this'getMediashotelsForm'], ['is_safe' => ['html']]),
  90.             new TwigFunction('mediashotelsAdmin_form', [$this'getMediashotelsFormAdmin'], ['is_safe' => ['html']]),
  91.             new TwigFunction('mediasannonceshotels_form', [$this'getMediasannonceshotelsForm'], ['is_safe' => ['html']]),
  92.             new TwigFunction('mediasrestaurants_form', [$this'getMediasrestaurantsForm'], ['is_safe' => ['html']]),
  93.             new TwigFunction('mediasrestaurantsAdmin_form', [$this'getMediasrestaurantsFormAdmin'], ['is_safe' => ['html']]),
  94.         ];
  95.     }
  96.     /**
  97.      * @return string
  98.      * @throws LoaderError
  99.      * @throws RuntimeError
  100.      * @throws SyntaxError
  101.      */
  102.     public function getContactForm(): string {
  103.         $newsletter = new Contacts();
  104.         $form $this->createForm(ContactsType::class, $newsletter);
  105.         return $this->twig->render('forms/__contact_form.html.twig', [
  106.             'form' => $form->createView(),
  107.         ]);
  108.     }
  109.     /**
  110.      * @return string
  111.      * @throws LoaderError
  112.      * @throws RuntimeError
  113.      * @throws SyntaxError
  114.      */
  115.     public function getNewsletterForm(): string {
  116.         $newsletter = new Newsletters();
  117.         $form $this->createForm(NewslettersType::class, $newsletter);
  118.         return $this->twig->render('forms/newsletter_form.html.twig', [
  119.             'form' => $form->createView(),
  120.             'newsletter' => $newsletter
  121.         ]);
  122.     }
  123.     /**
  124.      * @return string
  125.      * @throws LoaderError
  126.      * @throws RuntimeError
  127.      * @throws SyntaxError
  128.      */
  129.     public function getSearchForm(): string {
  130.         $data = new SearchchambresData();
  131.         $data->page $this->requestStack->get('page'1);
  132.         $formsearch $this->createForm(SearchFormChambresType::class, $data);
  133.         return $this->twig->render('pages/espacepro/searchs/__search_form.html.twig', [
  134.             'formsearch' => $formsearch->createView(),
  135.         ]);
  136.     }
  137.     /**
  138.      * @return string
  139.      * @throws LoaderError
  140.      * @throws RuntimeError
  141.      * @throws SyntaxError
  142.      */
  143.     public function getSearchFormRestaurant(): string {
  144.         $data = new SearchrestaurantData();
  145.         $data->page $this->requestStack->get('page'1);
  146.         $formsearch $this->createForm(\App\Form\Restaurants\SearchFormType::class, $data);
  147.         return $this->twig->render('pages/espacepro/searchs/__search_form_restaurant.html.twig', [
  148.             'formsearch' => $formsearch->createView(),
  149.         ]);
  150.     }
  151.     /**
  152.      * @return string
  153.      * @throws LoaderError
  154.      * @throws RuntimeError
  155.      * @throws SyntaxError
  156.      */
  157.     public function getDemandeStageForm(): string {
  158.         $demande = new Demandestages();
  159.         $form $this->createForm(DemandestagesType::class, $demande);
  160.         return $this->twig->render('forms/__demandestage_form.html.twig', [
  161.             'form' => $form->createView(),
  162.             'demande' => $demande,
  163.         ]);
  164.     }
  165.     /**
  166.      * @param int $actuality_id
  167.      * @return string
  168.      * @throws LoaderError
  169.      * @throws RuntimeError
  170.      * @throws SyntaxError
  171.      */
  172.     public function getMediasForm(int $actuality_id): string {
  173.         $medias = new Mediasactualites();
  174.         $form $this->createForm(MediasactualitesType::class, $medias);
  175.         return $this->twig->render('admin/actualites/mediasactualities/_form.html.twig', [
  176.             'form' => $form->createView(),
  177.             'id_actuality' => $actuality_id,
  178.         ]);
  179.     }
  180.     /**
  181.      * @param int $symbole_id
  182.      * @return string
  183.      * @throws LoaderError
  184.      * @throws RuntimeError
  185.      * @throws SyntaxError
  186.      */
  187.     public function getMediasFormSymbole(int $symbole_id): string {
  188.         $medias = new Mediassymboles();
  189.         $form $this->createForm(MediassymbolesType::class, $medias);
  190.         return $this->twig->render('admin/symboles/mediassymboles/_form.html.twig', [
  191.             'form' => $form->createView(),
  192.             'id_symbole' => $symbole_id,
  193.         ]);
  194.     }
  195.     /**
  196.      * @param int $agence_id
  197.      * @return string
  198.      * @throws LoaderError
  199.      * @throws RuntimeError
  200.      * @throws SyntaxError
  201.      */
  202.     public function getMediasFormAgence(int $agence_id): string {
  203.         $medias = new Mediasagencesvoyages();
  204.         $form $this->createForm(MediasagencesvoyagesType::class, $medias);
  205.         return $this->twig->render('admin/agencesvoyages/mediasagences/_form.html.twig', [
  206.             'form' => $form->createView(),
  207.             'id_agence' => $agence_id,
  208.         ]);
  209.     }
  210.     /**
  211.      * @param int $hotel_id
  212.      * @return string
  213.      * @throws LoaderError
  214.      * @throws RuntimeError
  215.      * @throws SyntaxError
  216.      */
  217.     public function getMediashotelsForm(int $hotel_id): string {
  218.         $medias = new Mediashotels();
  219.         $form $this->createForm(MediashotelsType::class, $medias);
  220.         return $this->twig->render('profils/hotelleries/hotels/mediashotels/_form.html.twig', [
  221.             'form' => $form->createView(),
  222.             'id_hotel' => $hotel_id,
  223.         ]);
  224.     }
  225.     /**
  226.      * @param int $hotel_id
  227.      * @return string
  228.      * @throws LoaderError
  229.      * @throws RuntimeError
  230.      * @throws SyntaxError
  231.      */
  232.     public function getMediashotelsFormAdmin(int $hotel_id): string {
  233.         $medias = new Mediashotels();
  234.         $form $this->createForm(MediashotelsType::class, $medias);
  235.         return $this->twig->render('admin/hotelleries/hotels/mediashotels/_form.html.twig', [
  236.             'form' => $form->createView(),
  237.             'id_hotel' => $hotel_id,
  238.         ]);
  239.     }
  240.     /**
  241.      * @param int $annonceshotel_id
  242.      * @return string
  243.      * @throws LoaderError
  244.      * @throws RuntimeError
  245.      * @throws SyntaxError
  246.      */
  247.     public function getMediasannonceshotelsForm(int $annonceshotel_id): string {
  248.         $medias = new Mediaannonceshotels();
  249.         $form $this->createForm(MediaannonceshotelsType::class, $medias);
  250.         return $this->twig->render('profils/hotelleries/annonceshotels/mediaannonceshotels/_form.html.twig', [
  251.             'form' => $form->createView(),
  252.             'id_annonceshotel' => $annonceshotel_id,
  253.         ]);
  254.     }
  255.     /**
  256.      * @param int $restaurant_id
  257.      * @return string
  258.      * @throws LoaderError
  259.      * @throws RuntimeError
  260.      * @throws SyntaxError
  261.      */
  262.     public function getMediasrestaurantsForm(int $restaurant_id): string {
  263.         $medias = new Mediasrestaurants();
  264.         $form $this->createForm(MediasrestaurantsType::class, $medias);
  265.         return $this->twig->render('profils/restaurations/restaurants/mediasrestaurants/_form.html.twig', [
  266.             'form' => $form->createView(),
  267.             'id_restaurant' => $restaurant_id,
  268.         ]);
  269.     }
  270.     /**
  271.      * @param int $restaurant_id
  272.      * @return string
  273.      * @throws LoaderError
  274.      * @throws RuntimeError
  275.      * @throws SyntaxError
  276.      */
  277.     public function getMediasrestaurantsFormAdmin(int $restaurant_id): string {
  278.         $medias = new Mediasrestaurants();
  279.         $form $this->createForm(MediasrestaurantsType::class, $medias);
  280.         return $this->twig->render('admin/restaurations/restaurants/mediasrestaurants/_form.html.twig', [
  281.             'form' => $form->createView(),
  282.             'id_restaurant' => $restaurant_id,
  283.         ]);
  284.     }
  285.     /**
  286.      * @param int $seminaireimage_id
  287.      * @return string
  288.      * @throws LoaderError
  289.      * @throws RuntimeError
  290.      * @throws SyntaxError
  291.      */
  292.     public function getMediasseminaireimageForm(int $seminaireimage_id): string {
  293.         $medias = new Mediaseminaires();
  294.         $form $this->createForm(MediaseminairesType::class, $medias);
  295.         return $this->twig->render('admin/seminaireimages/mediaseminaires/_form.html.twig', [
  296.             'form' => $form->createView(),
  297.             'id_seminaireimage' => $seminaireimage_id,
  298.         ]);
  299.     }
  300.     /**
  301.      * @param int $salon_id
  302.      * @return string
  303.      * @throws LoaderError
  304.      * @throws RuntimeError
  305.      * @throws SyntaxError
  306.      */
  307.     public function getMediassalonForm(int $salon_id): string {
  308.         $medias = new Mediasalons();
  309.         $form $this->createForm(MediasalonsType::class, $medias);
  310.         return $this->twig->render('admin/salons/mediasalons/_form.html.twig', [
  311.             'form' => $form->createView(),
  312.             'id_salon' => $salon_id,
  313.         ]);
  314.     }
  315.     /**
  316.      * @param int $post_id
  317.      * @return string
  318.      * @throws LoaderError
  319.      * @throws RuntimeError
  320.      * @throws SyntaxError
  321.      */
  322.     public function getMediaspostForm(int $post_id): string {
  323.         $medias = new Mediaposts();
  324.         $form $this->createForm(MediapostsType::class, $medias);
  325.         return $this->twig->render('admin/posts/mediaposts/_form.html.twig', [
  326.             'form' => $form->createView(),
  327.             'id_post' => $post_id,
  328.         ]);
  329.     }
  330.     /**
  331.      * @param int $article_id
  332.      * @return string
  333.      * @throws LoaderError
  334.      * @throws RuntimeError
  335.      * @throws SyntaxError
  336.      */
  337.     public function getMediasarticleForm(int $article_id): string {
  338.         $medias = new Mediaarticles();
  339.         $form $this->createForm(MediaarticlesType::class, $medias);
  340.         return $this->twig->render('admin/articles/mediaarticles/_form.html.twig', [
  341.             'form' => $form->createView(),
  342.             'id_article' => $article_id,
  343.         ]);
  344.     }
  345.     /**
  346.      * @param int $page_id
  347.      * @return string
  348.      * @throws LoaderError
  349.      * @throws RuntimeError
  350.      * @throws SyntaxError
  351.      */
  352.     public function getMediaspageForm(int $page_id): string {
  353.         $medias = new Mediapages();
  354.         $form $this->createForm(MediapagesType::class, $medias);
  355.         return $this->twig->render('admin/pages/mediapages/_form.html.twig', [
  356.             'form' => $form->createView(),
  357.             'id_page' => $page_id,
  358.         ]);
  359.     }
  360.     /**
  361.      * @param $type
  362.      * @param null $data
  363.      * @param array $options
  364.      * @return mixed
  365.      */
  366.     private function createForm($type$data null, array $options = array())
  367.     {
  368.         return $this->container->get('form.factory')->create($type$data$options);
  369.     }
  370. }