Refactor ChillTwigRoutingHelper to extend AbstractExtension and register Twig filters properly

This commit is contained in:
2025-12-19 11:56:44 +01:00
parent 4042cdd59c
commit 0d42ed9262
2 changed files with 10 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ use Twig\TwigFunction;
*
* The logic of the function is based on the original routing extension.
*/
class ChillTwigRoutingHelper
class ChillTwigRoutingHelper extends AbstractExtension
{
/**
* @var RoutingExtension
@@ -75,7 +75,13 @@ class ChillTwigRoutingHelper
return $this->originalExtension->getPath($name, $params, $relative);
}
#[\Twig\Attribute\AsTwigFilter('chill_return_path_label')]
public function getFilters(): array
{
return [
new TwigFilter('chill_return_path_label', $this->getLabelReturnPath(...)),
];
}
public function getLabelReturnPath($default)
{
$request = $this->requestStack->getCurrentRequest();

View File

@@ -29,6 +29,8 @@ services:
$originalExtension: '@twig.extension.routing'
autoconfigure: true
autowire: true
tags:
- { name: twig.extension }
Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension:
autoconfigure: true