DX: Add features to filterOrder

Allow to add single checkboxes and entitychoices to filter order
This commit is contained in:
2023-06-23 12:19:40 +02:00
parent 27f797d736
commit 659dff3d2c
6 changed files with 224 additions and 39 deletions

View File

@@ -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,
]);
}
}