vendor/ibexa/twig-components/src/bundle/Templating/Twig/ComponentExtension.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\TwigComponents\Templating\Twig;
  8. use Ibexa\Contracts\TwigComponents\Renderer\RendererInterface;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFunction;
  11. final class ComponentExtension extends AbstractExtension
  12. {
  13. private RendererInterface $renderer;
  14. public function __construct(RendererInterface $renderer)
  15. {
  16. $this->renderer = $renderer;
  17. }
  18. /**
  19. * @return \Twig\TwigFunction[]
  20. */
  21. public function getFunctions(): array
  22. {
  23. return [
  24. new TwigFunction(
  25. 'ibexa_twig_component_group',
  26. [$this, 'renderComponentGroup'],
  27. ['is_safe' => ['html']]
  28. ),
  29. new TwigFunction(
  30. 'ibexa_twig_component',
  31. [$this, 'renderComponent'],
  32. ['is_safe' => ['html']]
  33. ),
  34. ];
  35. }
  36. /**
  37. * @param array<mixed> $parameters
  38. */
  39. public function renderComponentGroup(string $group, array $parameters = []): string
  40. {
  41. return implode('', $this->renderer->renderGroup($group, $parameters));
  42. }
  43. /**
  44. * @param array<mixed> $parameters
  45. */
  46. public function renderComponent(string $group, string $id, array $parameters = []): string
  47. {
  48. return $this->renderer->renderSingle($group, $id, $parameters);
  49. }
  50. }