diff --git a/CHANGELOG.md b/CHANGELOG.md index 343879a3c..11c152c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,3 +65,9 @@ Version 1.5.10 - allow to group export in UI +Master branch +============= + +- improve return path functions and filters ; + + diff --git a/Templating/ChillTwigRoutingHelper.php b/Templating/ChillTwigRoutingHelper.php index 6e9bc900f..5bbd6abe2 100644 --- a/Templating/ChillTwigRoutingHelper.php +++ b/Templating/ChillTwigRoutingHelper.php @@ -5,6 +5,7 @@ namespace Chill\MainBundle\Templating; use Twig\Extension\AbstractExtension; use Twig\TwigFunction; +use Twig\TwigFilter; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Bridge\Twig\Extension\RoutingExtension; @@ -42,7 +43,15 @@ class ChillTwigRoutingHelper extends AbstractExtension return [ new TwigFunction('chill_return_path_or', [$this, 'getReturnPathOr'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ), new TwigFunction('chill_path_add_return_path', [$this, 'getPathAddReturnPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ), - new TwigFunction('chill_path_forward_return_path', [$this, 'getPathForwardReturnPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ) + new TwigFunction('chill_path_forward_return_path', [$this, 'getPathForwardReturnPath'], ['is_safe_callback' => [$this, 'isUrlGenerationSafe']] ), + + ]; + } + + public function getFilters() + { + return [ + new TwigFilter('chill_return_path_label', [$this, 'getLabelReturnPath']), ]; } @@ -51,6 +60,13 @@ class ChillTwigRoutingHelper extends AbstractExtension return $this->originalExtension->isUrlGenerationSafe($argsNode); } + public function getLabelReturnPath($default) + { + $request = $this->requestStack->getCurrentRequest(); + + return $request->query->get('returnPathLabel', null) ?? $default; + } + /** * Return the return path if it exists, or generate the path if not. * @@ -78,12 +94,16 @@ class ChillTwigRoutingHelper extends AbstractExtension * @param bool $relative * @return string */ - public function getPathAddReturnPath($name, $parameters = [], $relative = false) + public function getPathAddReturnPath($name, $parameters = [], $relative = false, $label = null) { $request = $this->requestStack->getCurrentRequest(); $parameters['returnPath'] = $request->getRequestUri(); + if ($label) { + $parameters['returnPathLabel'] = $label; + } + return $this->originalExtension->getPath($name, $parameters, $relative); }