vendor/sylius/sylius/src/Sylius/Bundle/UiBundle/Renderer/HtmlDebugTemplateBlockRenderer.php line 27

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\Renderer;
  12. use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
  13. /**
  14. * @experimental
  15. */
  16. final class HtmlDebugTemplateBlockRenderer implements TemplateBlockRendererInterface
  17. {
  18. public function __construct(private TemplateBlockRendererInterface $templateBlockRenderer)
  19. {
  20. }
  21. public function render(TemplateBlock $templateBlock, array $context = []): string
  22. {
  23. $shouldRenderHtmlDebug = strrpos($templateBlock->getTemplate(), '.html.twig') !== false;
  24. $renderedParts = [];
  25. if ($shouldRenderHtmlDebug) {
  26. $renderedParts[] = sprintf(
  27. '<!-- BEGIN BLOCK | event name: "%s", block name: "%s", template: "%s", priority: %d -->',
  28. $templateBlock->getEventName(),
  29. $templateBlock->getName(),
  30. $templateBlock->getTemplate(),
  31. $templateBlock->getPriority(),
  32. );
  33. }
  34. $renderedParts[] = $this->templateBlockRenderer->render($templateBlock, $context);
  35. if ($shouldRenderHtmlDebug) {
  36. $renderedParts[] = sprintf(
  37. '<!-- END BLOCK | event name: "%s", block name: "%s" -->',
  38. $templateBlock->getEventName(),
  39. $templateBlock->getName(),
  40. );
  41. }
  42. return implode("\n", $renderedParts);
  43. }
  44. }