Skip to content

Commit a61c21c

Browse files
committed
Fix retrieving hookable's configuration and data from the context
1 parent 8295d56 commit a61c21c

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

src/TwigHooks/src/Hookable/Renderer/HookableTemplateRenderer.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88
use Sylius\TwigHooks\Hookable\HookableTemplate;
99
use Sylius\TwigHooks\Provider\ConfigurationProviderInterface;
1010
use Sylius\TwigHooks\Provider\DataProviderInterface;
11+
use Sylius\TwigHooks\Twig\Runtime\HooksRuntime;
1112
use Twig\Environment as Twig;
1213

1314
final class HookableTemplateRenderer implements SupportableHookableRendererInterface
1415
{
15-
public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration';
16-
17-
public const HOOKABLE_DATA_PARAMETER = 'hookable_data';
18-
1916
public function __construct(
2017
private Twig $twig,
2118
private DataProviderInterface $dataProvider,
@@ -35,8 +32,8 @@ public function render(AbstractHookable $hookable, array $hookData = []): string
3532
$configuration = $this->configurationProvider->provide($hookable);
3633

3734
return $this->twig->render($hookable->getTarget(), [
38-
self::HOOKABLE_DATA_PARAMETER => $data,
39-
self::HOOKABLE_CONFIGURATION_PARAMETER => $configuration,
35+
HooksRuntime::HOOKABLE_DATA_PARAMETER => $data,
36+
HooksRuntime::HOOKABLE_CONFIGURATION_PARAMETER => $configuration,
4037
]);
4138
}
4239

src/TwigHooks/src/Twig/HooksExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ final class HooksExtension extends AbstractExtension
1515
public function getFunctions(): array
1616
{
1717
return [
18-
new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]),
19-
new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]),
18+
new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookableData'], ['needs_context' => true]),
19+
new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookableConfiguration'], ['needs_context' => true]),
2020
];
2121
}
2222

src/TwigHooks/src/Twig/Runtime/HooksRuntime.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
final class HooksRuntime implements RuntimeExtensionInterface
1515
{
16+
public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration';
17+
18+
public const HOOKABLE_DATA_PARAMETER = 'hookable_data';
19+
1620
private ?Stopwatch $stopwatch = null;
1721

1822
public function __construct (
@@ -27,21 +31,21 @@ public function __construct (
2731
}
2832

2933
/**
30-
* @param array{hook_data?: array<string, string>} $context
34+
* @param array{hookable_data?: array<string, string>} $context
3135
* @return array<string, string>
3236
*/
33-
public function getHookData(array $context): array
37+
public function getHookableData(array $context): array
3438
{
35-
return $context['hook_data'] ?? [];
39+
return $context[self::HOOKABLE_DATA_PARAMETER] ?? [];
3640
}
3741

3842
/**
39-
* @param array{hook_configuration?: array<string, string>} $context
43+
* @param array{hookable_configuration?: array<string, string>} $context
4044
* @return array<string, string>
4145
*/
42-
public function getHookConfiguration(array $context): array
46+
public function getHookableConfiguration(array $context): array
4347
{
44-
return $context['hook_configuration'] ?? [];
48+
return $context[self::HOOKABLE_CONFIGURATION_PARAMETER] ?? [];
4549
}
4650

4751
/**

src/TwigHooks/tests/Unit/Hookable/Renderer/HookableTemplateRendererTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Sylius\TwigHooks\Hookable\Renderer\HookableTemplateRenderer;
1111
use Sylius\TwigHooks\Provider\ConfigurationProviderInterface;
1212
use Sylius\TwigHooks\Provider\DataProviderInterface;
13+
use Sylius\TwigHooks\Twig\Runtime\HooksRuntime;
1314
use Tests\Sylius\TwigHooks\Utils\MotherObject\HookableComponentMotherObject;
1415
use Tests\Sylius\TwigHooks\Utils\MotherObject\HookableTemplateMotherObject;
1516
use Twig\Environment as Twig;
@@ -59,8 +60,8 @@ public function testItRendersHookableTemplate(): void
5960
$this->configurationProvider->expects($this->once())->method('provide')->willReturn(['some' => 'configuration']);
6061

6162
$this->twig->expects($this->once())->method('render')->with('some-template', [
62-
HookableTemplateRenderer::HOOKABLE_DATA_PARAMETER => ['some' => 'data'],
63-
HookableTemplateRenderer::HOOKABLE_CONFIGURATION_PARAMETER => ['some' => 'configuration'],
63+
HooksRuntime::HOOKABLE_DATA_PARAMETER => ['some' => 'data'],
64+
HooksRuntime::HOOKABLE_CONFIGURATION_PARAMETER => ['some' => 'configuration'],
6465
])->willReturn('some-rendered-template');
6566

6667
$hookable = HookableTemplateMotherObject::withTarget('some-template');

0 commit comments

Comments
 (0)