Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ class Configuration implements ConfigurationInterface
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('padam87_form_filter');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
return new TreeBuilder('padam87_form_filter');
}
}
6 changes: 3 additions & 3 deletions DependencyInjection/Padam87FormFilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Padam87\FormFilterBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration.
Expand All @@ -20,9 +20,9 @@ class Padam87FormFilterExtension extends Extension
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
36 changes: 16 additions & 20 deletions Form/RangeFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
Expand Down Expand Up @@ -42,26 +40,24 @@ public function configureOptions(OptionsResolver $resolver): void
'to_field_type' => TextType::class,
'to_field_options' => [],
'to_field_expr' => 'lte',
'filter' => function (Options $options) {
return function(QueryBuilder $qb, string $alias, array $value, string $field) use ($options): void {
if ($value['from'] != null) {
$parameter = $this->getParameterName($alias, $field, 'from');
'filter' => fn(Options $options) => function(QueryBuilder $qb, string $alias, array $value, string $field) use ($options): void {
if ($value['from'] != null) {
$parameter = $this->getParameterName($alias, $field, 'from');

$qb
->andWhere($qb->expr()->{$options['from_field_expr']}($alias . '.' . $field, ':' . $parameter))
->setParameter($parameter, $value['from'])
;
}
if ($value['to'] != null) {
$parameter = $this->getParameterName($alias, $field, 'to');
$qb
->andWhere($qb->expr()->{$options['from_field_expr']}($alias . '.' . $field, ':' . $parameter))
->setParameter($parameter, $value['from'])
;
}

if ($value['to'] != null) {
$parameter = $this->getParameterName($alias, $field, 'to');

$qb
->andWhere($qb->expr()->{$options['to_field_expr']}($alias . '.' . $field, ':' . $parameter))
->setParameter($parameter, $value['to'])
;
}
};
$qb
->andWhere($qb->expr()->{$options['to_field_expr']}($alias . '.' . $field, ':' . $parameter))
->setParameter($parameter, $value['to'])
;
}
},
]
)
Expand Down
2 changes: 1 addition & 1 deletion Service/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Filters
{
public function apply(QueryBuilder $qb, FormInterface $filters, ?string $rootAlias = null): void
{
$rootAlias = $rootAlias ?? $qb->getRootAliases()[0];
$rootAlias ??= $qb->getRootAliases()[0];

foreach ($filters->all() as $name => $filter) {
$ignoreNull = $filter->getConfig()->getOption('filter_ignore_null');
Expand Down
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
"psr-4": {"Padam87\\FormFilterBundle\\": ""}
},
"require": {
"php": "^8.0",
"symfony/config": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"symfony/form": "^6.0 || ^7.0",
"doctrine/orm": "^2.3 || ^3.0"
},
"suggest": {
"php": "^8.4",
"symfony/config": "^6.0 || ^7.0 || ^8.0",
"symfony/dependency-injection": "^6.0 || ^7.0 || ^8.0",
"symfony/form": "^6.0 || ^7.0 || ^8.0",
"doctrine/orm": "^2.3 || ^3.0 || ^8.0"
}
}