vendor/bitbag/cms-plugin/src/Twig/Runtime/RenderBlockRuntime.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file was created by developers working at BitBag
  4.  * Do you need more information about us and what we do? Visit our https://bitbag.io website!
  5.  * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
  6. */
  7. declare(strict_types=1);
  8. namespace BitBag\SyliusCmsPlugin\Twig\Runtime;
  9. use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;
  10. use BitBag\SyliusCmsPlugin\Resolver\BlockResourceResolverInterface;
  11. use Twig\Environment;
  12. final class RenderBlockRuntime implements RenderBlockRuntimeInterface
  13. {
  14.     /** @var BlockRepositoryInterface */
  15.     private $blockRepository;
  16.     /** @var BlockResourceResolverInterface */
  17.     private $blockResourceResolver;
  18.     /** @var Environment */
  19.     private $templatingEngine;
  20.     private const DEFAULT_TEMPLATE '@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig';
  21.     public function __construct(
  22.         BlockRepositoryInterface $blockRepository,
  23.         BlockResourceResolverInterface $blockResourceResolver,
  24.         Environment $templatingEngine
  25.     ) {
  26.         $this->blockRepository $blockRepository;
  27.         $this->blockResourceResolver $blockResourceResolver;
  28.         $this->templatingEngine $templatingEngine;
  29.     }
  30.     public function renderBlock(string $code, ?string $template null): string
  31.     {
  32.         $block $this->blockResourceResolver->findOrLog($code);
  33.         if (null !== $block) {
  34.             $template $template ?? self::DEFAULT_TEMPLATE;
  35.             return $this->templatingEngine->render($template, ['block' => $block]);
  36.         }
  37.         return '';
  38.     }
  39. }