Skip to content

Commit ce2c98f

Browse files
committed
Fixed bug: Missing context in twig renderer
1 parent 81d4e9d commit ce2c98f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/BlockRenderer/TwigBlockRenderer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function render(Block $block): string
2929
$template = sprintf('@SetonoEditorJS/block/%s.html.twig', $blockName);
3030

3131
try {
32-
return $this->twig->render($template);
32+
return $this->twig->render($template, [
33+
'block' => $block,
34+
]);
3335
} catch (\Throwable $e) {
3436
throw TwigRenderException::fromThrowable($template, $e);
3537
}

tests/BlockRenderer/TwigBlockRendererTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ final class TwigBlockRendererTest extends TestCase
2424
*/
2525
public function it_renders(): void
2626
{
27+
$block = new SimpleImageBlock('id');
28+
2729
$twig = $this->prophesize(Environment::class);
28-
$twig->render('@SetonoEditorJS/block/simple_image.html.twig')->shouldBeCalledOnce()->willReturn('');
30+
$twig->render('@SetonoEditorJS/block/simple_image.html.twig', [
31+
'block' => $block,
32+
])->shouldBeCalledOnce()->willReturn('');
2933

3034
$renderer = new TwigBlockRenderer($twig->reveal());
31-
$renderer->render(new SimpleImageBlock('id'));
35+
$renderer->render($block);
3236
}
3337

3438
/**
@@ -47,11 +51,15 @@ public function it_throws_twig_render_exception_if_the_template_cannot_be_render
4751
{
4852
$this->expectException(TwigRenderException::class);
4953

54+
$block = new SimpleImageBlock('id');
55+
5056
$twig = $this->prophesize(Environment::class);
51-
$twig->render('@SetonoEditorJS/block/simple_image.html.twig')->willThrow(new LoaderError('The template does not exist'));
57+
$twig->render('@SetonoEditorJS/block/simple_image.html.twig', [
58+
'block' => $block,
59+
])->willThrow(new LoaderError('The template does not exist'));
5260

5361
$renderer = new TwigBlockRenderer($twig->reveal());
54-
$renderer->render(new SimpleImageBlock('id'));
62+
$renderer->render($block);
5563
}
5664
}
5765

0 commit comments

Comments
 (0)