<?php
namespace App\Twig\Runtime;
use App\Filter\Front\GlobalSearch;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Environment;
use Twig\Extension\RuntimeExtensionInterface;
class SearchRuntime implements RuntimeExtensionInterface
{
private FormFactoryInterface $factory;
public function __construct(FormFactoryInterface $factory)
{
$this->factory = $factory;
}
/**
* @param Environment $twig
* @return string
* @throws \Twig\Error\LoaderError
* @throws \Twig\Error\RuntimeError
* @throws \Twig\Error\SyntaxError
*/
public function searchForm(Environment $twig): string
{
$form = $this->factory->create(GlobalSearch::class);
$form->handleRequest(Request::createFromGlobals());
return $twig->render('Form/search_form.html.twig', [
'form' => $form->createView(),
]);
}
}