diff --git a/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php b/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php index c37f25e4..63d74174 100644 --- a/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php +++ b/src/TwigHooks/src/Twig/Runtime/HooksRuntime.php @@ -69,12 +69,11 @@ public function renderHook(string|array $hookNames, array $hookContext = [], ?Ho { $hookNames = is_string($hookNames) ? [$hookNames] : $hookNames; + $context = $this->getContext($hookContext, $hookableMetadata); $prefixes = $this->getPrefixes($hookContext, $hookableMetadata); if (false === $this->enableAutoprefixing || [] === $prefixes) { - $hookContext['_prefixes'] = $hookNames; - - return $this->hookRenderer->render($hookNames, $hookContext); + return $this->hookRenderer->render($hookNames, $context); } $prefixedHookNames = []; @@ -85,9 +84,7 @@ public function renderHook(string|array $hookNames, array $hookContext = [], ?Ho } } - $hookContext['_prefixes'] = $prefixedHookNames; - - return $this->hookRenderer->render($prefixedHookNames, $hookContext); + return $this->hookRenderer->render($prefixedHookNames, $context); } /** @@ -109,4 +106,19 @@ private function getPrefixes(array $hookContext, ?HookableMetadata $hookableMeta return $prefixes; } + + /** + * @param array $hookContext + * @return array + */ + private function getContext(array $hookContext, ?HookableMetadata $hookableMetadata): array + { + $context = []; + + if ($hookableMetadata !== null) { + $context = $hookableMetadata->context->all(); + } + + return array_merge($context, $hookContext); + } }