<?php
namespace App\Extensions\Twig;
use App\Data\SearchchambresData;
use App\Data\SearchrestaurantData;
use App\Entity\Agencesvoyages\Mediasagencesvoyages;
use App\Entity\Contacts\Contacts;
use App\Entity\Contacts\Newsletters;
use App\Entity\Demandestages;
use App\Entity\Hotels\Mediaannonceshotels;
use App\Entity\Hotels\Mediashotels;
use App\Entity\Articles\Mediaarticles;
use App\Entity\Pages\Mediapages;
use App\Entity\Posts\Mediaposts;
use App\Entity\Actualites\Mediasactualites;
use App\Entity\Salons\Mediasalons;
use App\Entity\Mediaseminaires;
use App\Entity\Restaurants\Mediasrestaurants;
use App\Entity\Symboles\Mediassymboles;
use App\Form\Agencesvoyages\MediasagencesvoyagesType;
use App\Form\Contacts\ContactsType;
use App\Form\Contacts\NewslettersType;
use App\Form\DemandestagesType;
use App\Form\Hotels\MediaannonceshotelsType;
use App\Form\Hotels\MediashotelsType;
use App\Form\Hotels\SearchFormChambresType;
use App\Form\Articles\MediaarticlesType;
use App\Form\Pages\MediapagesType;
use App\Form\Posts\MediapostsType;
use App\Form\Actualites\MediasactualitesType;
use App\Form\Salons\MediasalonsType;
use App\Form\MediaseminairesType;
use App\Form\Restaurants\MediasrestaurantsType;
use App\Form\Symboles\MediassymbolesType;
use Psr\Container\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Cache\CacheInterface;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class FormsExtension extends AbstractExtension
{
/**
* @var Environment
*/
private $twig;
/**
* @var CacheInterface
*/
private $cache;
/**
* @var ContainerInterface
*/
private $container;
/**
* @var RequestStack
*/
private $requestStack;
public function __construct(
Environment $twig,
CacheInterface $cache,
RequestStack $requestStack,
ContainerInterface $container
)
{
$this->twig = $twig;
$this->cache = $cache;
$this->container = $container;
$this->requestStack = $requestStack->getCurrentRequest();
}
public function getFunctions(): array
{
return [
new TwigFunction('contact_form', [$this, 'getContactForm'], ['is_safe' => ['html']]),
new TwigFunction('newsletter_form', [$this, 'getNewsletterForm'], ['is_safe' => ['html']]),
new TwigFunction('search_form', [$this, 'getSearchForm'], ['is_safe' => ['html']]),
new TwigFunction('search_form_restaurant', [$this, 'getSearchFormRestaurant'], ['is_safe' => ['html']]),
new TwigFunction('demande_stage_form', [$this, 'getDemandeStageForm'], ['is_safe' => ['html']]),
new TwigFunction('medias_form', [$this, 'getMediasForm'], ['is_safe' => ['html']]),
new TwigFunction('medias_form_symbole', [$this, 'getMediasFormSymbole'], ['is_safe' => ['html']]),
new TwigFunction('medias_form_agence', [$this, 'getMediasFormAgence'], ['is_safe' => ['html']]),
new TwigFunction('mediasseminaireimages_form', [$this, 'getMediasseminaireimageForm'], ['is_safe' => ['html']]),
new TwigFunction('mediassalon_form', [$this, 'getMediassalonForm'], ['is_safe' => ['html']]),
new TwigFunction('mediaspost_form', [$this, 'getMediaspostForm'], ['is_safe' => ['html']]),
new TwigFunction('mediasarticle_form', [$this, 'getMediasarticleForm'], ['is_safe' => ['html']]),
new TwigFunction('mediaspage_form', [$this, 'getMediaspageForm'], ['is_safe' => ['html']]),
new TwigFunction('mediashotels_form', [$this, 'getMediashotelsForm'], ['is_safe' => ['html']]),
new TwigFunction('mediashotelsAdmin_form', [$this, 'getMediashotelsFormAdmin'], ['is_safe' => ['html']]),
new TwigFunction('mediasannonceshotels_form', [$this, 'getMediasannonceshotelsForm'], ['is_safe' => ['html']]),
new TwigFunction('mediasrestaurants_form', [$this, 'getMediasrestaurantsForm'], ['is_safe' => ['html']]),
new TwigFunction('mediasrestaurantsAdmin_form', [$this, 'getMediasrestaurantsFormAdmin'], ['is_safe' => ['html']]),
];
}
/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getContactForm(): string {
$newsletter = new Contacts();
$form = $this->createForm(ContactsType::class, $newsletter);
return $this->twig->render('forms/__contact_form.html.twig', [
'form' => $form->createView(),
]);
}
/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getNewsletterForm(): string {
$newsletter = new Newsletters();
$form = $this->createForm(NewslettersType::class, $newsletter);
return $this->twig->render('forms/newsletter_form.html.twig', [
'form' => $form->createView(),
'newsletter' => $newsletter
]);
}
/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getSearchForm(): string {
$data = new SearchchambresData();
$data->page = $this->requestStack->get('page', 1);
$formsearch = $this->createForm(SearchFormChambresType::class, $data);
return $this->twig->render('pages/espacepro/searchs/__search_form.html.twig', [
'formsearch' => $formsearch->createView(),
]);
}
/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getSearchFormRestaurant(): string {
$data = new SearchrestaurantData();
$data->page = $this->requestStack->get('page', 1);
$formsearch = $this->createForm(\App\Form\Restaurants\SearchFormType::class, $data);
return $this->twig->render('pages/espacepro/searchs/__search_form_restaurant.html.twig', [
'formsearch' => $formsearch->createView(),
]);
}
/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getDemandeStageForm(): string {
$demande = new Demandestages();
$form = $this->createForm(DemandestagesType::class, $demande);
return $this->twig->render('forms/__demandestage_form.html.twig', [
'form' => $form->createView(),
'demande' => $demande,
]);
}
/**
* @param int $actuality_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasForm(int $actuality_id): string {
$medias = new Mediasactualites();
$form = $this->createForm(MediasactualitesType::class, $medias);
return $this->twig->render('admin/actualites/mediasactualities/_form.html.twig', [
'form' => $form->createView(),
'id_actuality' => $actuality_id,
]);
}
/**
* @param int $symbole_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasFormSymbole(int $symbole_id): string {
$medias = new Mediassymboles();
$form = $this->createForm(MediassymbolesType::class, $medias);
return $this->twig->render('admin/symboles/mediassymboles/_form.html.twig', [
'form' => $form->createView(),
'id_symbole' => $symbole_id,
]);
}
/**
* @param int $agence_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasFormAgence(int $agence_id): string {
$medias = new Mediasagencesvoyages();
$form = $this->createForm(MediasagencesvoyagesType::class, $medias);
return $this->twig->render('admin/agencesvoyages/mediasagences/_form.html.twig', [
'form' => $form->createView(),
'id_agence' => $agence_id,
]);
}
/**
* @param int $hotel_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediashotelsForm(int $hotel_id): string {
$medias = new Mediashotels();
$form = $this->createForm(MediashotelsType::class, $medias);
return $this->twig->render('profils/hotelleries/hotels/mediashotels/_form.html.twig', [
'form' => $form->createView(),
'id_hotel' => $hotel_id,
]);
}
/**
* @param int $hotel_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediashotelsFormAdmin(int $hotel_id): string {
$medias = new Mediashotels();
$form = $this->createForm(MediashotelsType::class, $medias);
return $this->twig->render('admin/hotelleries/hotels/mediashotels/_form.html.twig', [
'form' => $form->createView(),
'id_hotel' => $hotel_id,
]);
}
/**
* @param int $annonceshotel_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasannonceshotelsForm(int $annonceshotel_id): string {
$medias = new Mediaannonceshotels();
$form = $this->createForm(MediaannonceshotelsType::class, $medias);
return $this->twig->render('profils/hotelleries/annonceshotels/mediaannonceshotels/_form.html.twig', [
'form' => $form->createView(),
'id_annonceshotel' => $annonceshotel_id,
]);
}
/**
* @param int $restaurant_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasrestaurantsForm(int $restaurant_id): string {
$medias = new Mediasrestaurants();
$form = $this->createForm(MediasrestaurantsType::class, $medias);
return $this->twig->render('profils/restaurations/restaurants/mediasrestaurants/_form.html.twig', [
'form' => $form->createView(),
'id_restaurant' => $restaurant_id,
]);
}
/**
* @param int $restaurant_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasrestaurantsFormAdmin(int $restaurant_id): string {
$medias = new Mediasrestaurants();
$form = $this->createForm(MediasrestaurantsType::class, $medias);
return $this->twig->render('admin/restaurations/restaurants/mediasrestaurants/_form.html.twig', [
'form' => $form->createView(),
'id_restaurant' => $restaurant_id,
]);
}
/**
* @param int $seminaireimage_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasseminaireimageForm(int $seminaireimage_id): string {
$medias = new Mediaseminaires();
$form = $this->createForm(MediaseminairesType::class, $medias);
return $this->twig->render('admin/seminaireimages/mediaseminaires/_form.html.twig', [
'form' => $form->createView(),
'id_seminaireimage' => $seminaireimage_id,
]);
}
/**
* @param int $salon_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediassalonForm(int $salon_id): string {
$medias = new Mediasalons();
$form = $this->createForm(MediasalonsType::class, $medias);
return $this->twig->render('admin/salons/mediasalons/_form.html.twig', [
'form' => $form->createView(),
'id_salon' => $salon_id,
]);
}
/**
* @param int $post_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediaspostForm(int $post_id): string {
$medias = new Mediaposts();
$form = $this->createForm(MediapostsType::class, $medias);
return $this->twig->render('admin/posts/mediaposts/_form.html.twig', [
'form' => $form->createView(),
'id_post' => $post_id,
]);
}
/**
* @param int $article_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediasarticleForm(int $article_id): string {
$medias = new Mediaarticles();
$form = $this->createForm(MediaarticlesType::class, $medias);
return $this->twig->render('admin/articles/mediaarticles/_form.html.twig', [
'form' => $form->createView(),
'id_article' => $article_id,
]);
}
/**
* @param int $page_id
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
*/
public function getMediaspageForm(int $page_id): string {
$medias = new Mediapages();
$form = $this->createForm(MediapagesType::class, $medias);
return $this->twig->render('admin/pages/mediapages/_form.html.twig', [
'form' => $form->createView(),
'id_page' => $page_id,
]);
}
/**
* @param $type
* @param null $data
* @param array $options
* @return mixed
*/
private function createForm($type, $data = null, array $options = array())
{
return $this->container->get('form.factory')->create($type, $data, $options);
}
}