vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Twig/TemplateEventExtension.php line 41

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\UiBundle\Twig;
  12. use Sylius\Bundle\UiBundle\Renderer\TemplateEventRendererInterface;
  13. use Twig\Extension\AbstractExtension;
  14. use Twig\TwigFunction;
  15. /**
  16.  * @experimental
  17.  */
  18. final class TemplateEventExtension extends AbstractExtension
  19. {
  20.     public function __construct(private TemplateEventRendererInterface $templateEventRenderer)
  21.     {
  22.     }
  23.     public function getFunctions(): array
  24.     {
  25.         return [
  26.             new TwigFunction('sylius_template_event', [$this'render'], ['is_safe' => ['html']]),
  27.         ];
  28.     }
  29.     /**
  30.      * @param string|string[] $eventName
  31.      */
  32.     public function render(string|array $eventName, array $context = []): string
  33.     {
  34.         return $this->templateEventRenderer->render((array) $eventName$context);
  35.     }
  36. }