mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-10 06:08:25 +00:00
Refactor ChillTwigRoutingHelper to extend AbstractExtension and improve Twig functionality
- Updated `ChillTwigRoutingHelper` to extend `AbstractExtension` for consistency with Twig best practices. - Moved `chill_return_path_label` from a Twig attribute to a filter within `getFilters`. - Removed unnecessary dependency on `RequestStack` in `services/templating.yaml`.
This commit is contained in:
@@ -13,7 +13,12 @@ namespace Chill\MainBundle\Templating;
|
|||||||
|
|
||||||
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
use Symfony\Bridge\Twig\Extension\RoutingExtension;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
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\Node\Node;
|
||||||
|
use Twig\TwigFilter;
|
||||||
use Twig\TwigFunction;
|
use Twig\TwigFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -21,7 +26,7 @@ use Twig\TwigFunction;
|
|||||||
*
|
*
|
||||||
* The logic of the function is based on the original routing extension.
|
* The logic of the function is based on the original routing extension.
|
||||||
*/
|
*/
|
||||||
class ChillTwigRoutingHelper
|
class ChillTwigRoutingHelper extends AbstractExtension
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var RoutingExtension
|
* @var RoutingExtension
|
||||||
@@ -41,7 +46,7 @@ class ChillTwigRoutingHelper
|
|||||||
$this->originalExtension = $originalExtension;
|
$this->originalExtension = $originalExtension;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFunctions()
|
public function getFunctions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
new TwigFunction('chill_return_path_or', $this->getReturnPathOr(...), ['is_safe_callback' => $this->isUrlGenerationSafe(...)]),
|
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);
|
return $this->originalExtension->getPath($name, $params, $relative);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[\Twig\Attribute\AsTwigFilter('chill_return_path_label')]
|
|
||||||
public function getLabelReturnPath($default)
|
public function getLabelReturnPath($default)
|
||||||
{
|
{
|
||||||
$request = $this->requestStack->getCurrentRequest();
|
$request = $this->requestStack->getCurrentRequest();
|
||||||
@@ -149,4 +153,11 @@ class ChillTwigRoutingHelper
|
|||||||
{
|
{
|
||||||
return $this->originalExtension->isUrlGenerationSafe($argsNode);
|
return $this->originalExtension->isUrlGenerationSafe($argsNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFilters(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
new TwigFilter('chill_return_path_label', $this->getLabelReturnPath(...)),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ services:
|
|||||||
|
|
||||||
Chill\MainBundle\Templating\ChillTwigRoutingHelper:
|
Chill\MainBundle\Templating\ChillTwigRoutingHelper:
|
||||||
arguments:
|
arguments:
|
||||||
$requestStack: '@Symfony\Component\HttpFoundation\RequestStack'
|
|
||||||
$originalExtension: '@twig.extension.routing'
|
$originalExtension: '@twig.extension.routing'
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
autowire: true
|
autowire: true
|
||||||
|
|||||||
Reference in New Issue
Block a user