mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 23:53:50 +00:00
DX: Add features to filterOrder
Allow to add single checkboxes and entitychoices to filter order
This commit is contained in:
@@ -13,6 +13,8 @@ namespace Chill\MainBundle\Form\Type\Listing;
|
||||
|
||||
use Chill\MainBundle\Form\Type\ChillDateType;
|
||||
use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SearchType;
|
||||
@@ -27,13 +29,6 @@ use function count;
|
||||
|
||||
final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
{
|
||||
private RequestStack $requestStack;
|
||||
|
||||
public function __construct(RequestStack $requestStack)
|
||||
{
|
||||
$this->requestStack = $requestStack;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
/** @var FilterOrderHelper $helper */
|
||||
@@ -71,6 +66,25 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add($checkboxesBuilder);
|
||||
}
|
||||
|
||||
if ([] !== $helper->getEntityChoices()) {
|
||||
$entityChoicesBuilder = $builder->create('entity_choices', null, ['compound' => true]);
|
||||
|
||||
foreach ($helper->getEntityChoices() as $key => [
|
||||
'label' => $label, 'choices' => $choices, 'options' => $opts, 'class' => $class
|
||||
]) {
|
||||
$entityChoicesBuilder->add($key, EntityType::class, [
|
||||
'label' => $label,
|
||||
'choices' => $choices,
|
||||
'class' => $class,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
...$opts,
|
||||
]);
|
||||
}
|
||||
|
||||
$builder->add($entityChoicesBuilder);
|
||||
}
|
||||
|
||||
if (0 < count($helper->getDateRanges())) {
|
||||
$dateRangesBuilder = $builder->create('dateRanges', null, ['compound' => true]);
|
||||
|
||||
@@ -97,28 +111,14 @@ final class FilterOrderType extends \Symfony\Component\Form\AbstractType
|
||||
$builder->add($dateRangesBuilder);
|
||||
}
|
||||
|
||||
foreach ($this->requestStack->getCurrentRequest()->query->getIterator() as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'q':
|
||||
case 'checkboxes' . $key:
|
||||
case $key . '_from':
|
||||
case $key . '_to':
|
||||
break;
|
||||
if ([] !== $helper->getSingleCheckbox()) {
|
||||
$singleCheckBoxBuilder = $builder->create('single_checkboxes', null, ['compound' => true]);
|
||||
|
||||
case 'page':
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => 1,
|
||||
]);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
$builder->add($key, HiddenType::class, [
|
||||
'data' => $value,
|
||||
]);
|
||||
|
||||
break;
|
||||
foreach ($helper->getSingleCheckbox() as $name => ['label' => $label]) {
|
||||
$singleCheckBoxBuilder->add($name, CheckboxType::class, ['label' => $label, 'required' => false]);
|
||||
}
|
||||
|
||||
$builder->add($singleCheckBoxBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user