diff --git a/src/Bundle/ChillMainBundle/Templating/ChillTwigRoutingHelper.php b/src/Bundle/ChillMainBundle/Templating/ChillTwigRoutingHelper.php index b6a193221..ea61095cf 100644 --- a/src/Bundle/ChillMainBundle/Templating/ChillTwigRoutingHelper.php +++ b/src/Bundle/ChillMainBundle/Templating/ChillTwigRoutingHelper.php @@ -13,7 +13,12 @@ namespace Chill\MainBundle\Templating; use Symfony\Bridge\Twig\Extension\RoutingExtension; use Symfony\Component\HttpFoundation\RequestStack; +use Twig\Attribute\AsTwigFunction; +use Twig\ExpressionParser\ExpressionParserInterface; +use Twig\Extension\AbstractExtension; +use Twig\Extension\ExtensionInterface; use Twig\Node\Node; +use Twig\TwigFilter; use Twig\TwigFunction; /** @@ -21,7 +26,7 @@ use Twig\TwigFunction; * * The logic of the function is based on the original routing extension. */ -class ChillTwigRoutingHelper +class ChillTwigRoutingHelper extends AbstractExtension { /** * @var RoutingExtension @@ -41,7 +46,7 @@ class ChillTwigRoutingHelper $this->originalExtension = $originalExtension; } - public function getFunctions() + public function getFunctions(): array { return [ new TwigFunction('chill_return_path_or', $this->getReturnPathOr(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]), @@ -73,7 +78,6 @@ class ChillTwigRoutingHelper return $this->originalExtension->getPath($name, $params, $relative); } - #[\Twig\Attribute\AsTwigFilter('chill_return_path_label')] public function getLabelReturnPath($default) { $request = $this->requestStack->getCurrentRequest(); @@ -149,4 +153,11 @@ class ChillTwigRoutingHelper { return $this->originalExtension->isUrlGenerationSafe($argsNode); } + + public function getFilters(): array + { + return [ + new TwigFilter('chill_return_path_label', $this->getLabelReturnPath(...)), + ]; + } } diff --git a/src/Bundle/ChillMainBundle/config/services/templating.yaml b/src/Bundle/ChillMainBundle/config/services/templating.yaml index eeb20d161..ee56ba8f6 100644 --- a/src/Bundle/ChillMainBundle/config/services/templating.yaml +++ b/src/Bundle/ChillMainBundle/config/services/templating.yaml @@ -26,7 +26,6 @@ services: Chill\MainBundle\Templating\ChillTwigRoutingHelper: arguments: - $requestStack: '@Symfony\Component\HttpFoundation\RequestStack' $originalExtension: '@twig.extension.routing' autoconfigure: true autowire: true