Skip to content

Commit

Permalink
[TwigHooks] Fix automatically merging the current hook and current ho…
Browse files Browse the repository at this point in the history
…okable contexts
  • Loading branch information
jakubtobiasz committed Apr 22, 2024
1 parent c5b6ee3 commit 496f1c8
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/TwigHooks/src/Twig/Runtime/HooksRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
}

/**
Expand All @@ -109,4 +106,19 @@ private function getPrefixes(array $hookContext, ?HookableMetadata $hookableMeta

return $prefixes;
}

/**
* @param array<string, mixed> $hookContext
* @return array<string, mixed>
*/
private function getContext(array $hookContext, ?HookableMetadata $hookableMetadata): array
{
$context = [];

if ($hookableMetadata !== null) {
$context = $hookableMetadata->context->all();
}

return array_merge($context, $hookContext);
}
}

0 comments on commit 496f1c8

Please sign in to comment.