src/Twig/Runtime/SearchRuntime.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Twig\Runtime;
  3. use App\Filter\Front\GlobalSearch;
  4. use Symfony\Component\Form\FormFactoryInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\RequestStack;
  7. use Twig\Environment;
  8. use Twig\Extension\RuntimeExtensionInterface;
  9. class SearchRuntime implements RuntimeExtensionInterface
  10. {
  11. private FormFactoryInterface $factory;
  12. public function __construct(FormFactoryInterface $factory)
  13. {
  14. $this->factory = $factory;
  15. }
  16. /**
  17. * @param Environment $twig
  18. * @return string
  19. * @throws \Twig\Error\LoaderError
  20. * @throws \Twig\Error\RuntimeError
  21. * @throws \Twig\Error\SyntaxError
  22. */
  23. public function searchForm(Environment $twig): string
  24. {
  25. $form = $this->factory->create(GlobalSearch::class);
  26. $form->handleRequest(Request::createFromGlobals());
  27. return $twig->render('Form/search_form.html.twig', [
  28. 'form' => $form->createView(),
  29. ]);
  30. }
  31. }