Skip to content

Commit

Permalink
Fix retrieving hookable's configuration and data from the context
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Dec 18, 2023
1 parent 8295d56 commit fbcaf5d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
use Sylius\TwigHooks\Hookable\HookableTemplate;
use Sylius\TwigHooks\Provider\ConfigurationProviderInterface;
use Sylius\TwigHooks\Provider\DataProviderInterface;
use Sylius\TwigHooks\Twig\Runtime\HooksRuntime;
use Twig\Environment as Twig;

final class HookableTemplateRenderer implements SupportableHookableRendererInterface
{
public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration';

public const HOOKABLE_DATA_PARAMETER = 'hookable_data';

public function __construct(
private Twig $twig,
private DataProviderInterface $dataProvider,
Expand All @@ -35,8 +32,8 @@ public function render(AbstractHookable $hookable, array $hookData = []): string
$configuration = $this->configurationProvider->provide($hookable);

return $this->twig->render($hookable->getTarget(), [
self::HOOKABLE_DATA_PARAMETER => $data,
self::HOOKABLE_CONFIGURATION_PARAMETER => $configuration,
HooksRuntime::HOOKABLE_DATA_PARAMETER => $data,
HooksRuntime::HOOKABLE_CONFIGURATION_PARAMETER => $configuration,
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/TwigHooks/src/Twig/HooksExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class HooksExtension extends AbstractExtension
public function getFunctions(): array
{
return [
new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]),
new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookData'], ['needs_context' => true]),
new TwigFunction('get_hook_data', [HooksRuntime::class, 'getHookableData'], ['needs_context' => true]),
new TwigFunction('get_hook_configuration', [HooksRuntime::class, 'getHookableConfiguration'], ['needs_context' => true]),
];
}

Expand Down
16 changes: 10 additions & 6 deletions src/TwigHooks/src/Twig/Runtime/HooksRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

final class HooksRuntime implements RuntimeExtensionInterface
{
public const HOOKABLE_CONFIGURATION_PARAMETER = 'hookable_configuration';

public const HOOKABLE_DATA_PARAMETER = 'hookable_data';

private ?Stopwatch $stopwatch = null;

public function __construct (
Expand All @@ -27,21 +31,21 @@ public function __construct (
}

/**
* @param array{hook_data?: array<string, string>} $context
* @param array{hookable_data?: array<string, string>} $context
* @return array<string, string>
*/
public function getHookData(array $context): array
public function getHookableData(array $context): array
{
return $context['hook_data'] ?? [];
return $context[self::HOOKABLE_DATA_PARAMETER] ?? [];
}

/**
* @param array{hook_configuration?: array<string, string>} $context
* @param array{hookable_configuration?: array<string, string>} $context
* @return array<string, string>
*/
public function getHookConfiguration(array $context): array
public function getHookableConfiguration(array $context): array
{
return $context['hook_configuration'] ?? [];
return $context[self::HOOKABLE_CONFIGURATION_PARAMETER] ?? [];
}

/**
Expand Down

0 comments on commit fbcaf5d

Please sign in to comment.