mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
improve return path and label functions
This commit is contained in:
parent
dc1bac05ee
commit
77a4f52fdd
@ -65,3 +65,9 @@ Version 1.5.10
|
||||
|
||||
- allow to group export in UI
|
||||
|
||||
Master branch
|
||||
=============
|
||||
|
||||
- improve return path functions and filters ;
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user