mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 11:03:50 +00:00
DX: Add features to filterOrder
Allow to add single checkboxes and entitychoices to filter order
This commit is contained in:
@@ -11,13 +11,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Templating\Listing;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Error\RuntimeError;
|
||||
use Twig\Error\SyntaxError;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class Templating extends AbstractExtension
|
||||
{
|
||||
public function getFilters()
|
||||
public function __construct(
|
||||
private readonly RequestStack $requestStack,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('chill_render_filter_order_helper', [$this, 'renderFilterOrderHelper'], [
|
||||
@@ -26,16 +36,41 @@ class Templating extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws SyntaxError
|
||||
* @throws RuntimeError
|
||||
* @throws LoaderError
|
||||
*/
|
||||
public function renderFilterOrderHelper(
|
||||
Environment $environment,
|
||||
FilterOrderHelper $helper,
|
||||
?string $template = '@ChillMain/FilterOrder/base.html.twig',
|
||||
?array $options = []
|
||||
) {
|
||||
): string {
|
||||
$otherParameters = [];
|
||||
|
||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||
switch ($key) {
|
||||
case FilterOrderHelper::FORM_NAME:
|
||||
break;
|
||||
|
||||
case PaginatorFactory::DEFAULT_CURRENT_PAGE_KEY:
|
||||
// when filtering, go back to page 1
|
||||
$otherParameters[PaginatorFactory::DEFAULT_CURRENT_PAGE_KEY] = 1;
|
||||
|
||||
break;
|
||||
default:
|
||||
$otherParameters[$key] = $value;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $environment->render($template, [
|
||||
'helper' => $helper,
|
||||
'form' => $helper->buildForm()->createView(),
|
||||
'options' => $options,
|
||||
'otherParameters' => $otherParameters,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user