]>
Commit | Line | Data |
---|---|---|
26864574 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Filter; | |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
6 | use Symfony\Component\Form\FormBuilderInterface; | |
7 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
443cecd2 | 8 | use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface; |
26864574 NL |
9 | |
10 | class EntryFilterType extends AbstractType | |
11 | { | |
12 | public function buildForm(FormBuilderInterface $builder, array $options) | |
13 | { | |
3c5b025a NL |
14 | $builder |
15 | ->add('readingTime', 'filter_number_range') | |
16 | ->add('createdAt', 'filter_date_range', array( | |
17 | 'left_date_options' => array( | |
18 | 'attr' => array( | |
8ce32af6 JB |
19 | 'placeholder' => 'dd/mm/yyyy', |
20 | ), | |
3c5b025a | 21 | 'format' => 'dd/MM/yyyy', |
8ce32af6 | 22 | 'widget' => 'single_text', |
3c5b025a NL |
23 | ), |
24 | 'right_date_options' => array( | |
25 | 'attr' => array( | |
8ce32af6 JB |
26 | 'placeholder' => 'dd/mm/yyyy', |
27 | ), | |
3c5b025a | 28 | 'format' => 'dd/MM/yyyy', |
8ce32af6 JB |
29 | 'widget' => 'single_text', |
30 | ), | |
31 | )) | |
443cecd2 | 32 | ->add('domainName', 'filter_text', array( |
8ce32af6 | 33 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { |
443cecd2 NL |
34 | $value = $values['value']; |
35 | if (strlen($value) <= 3 || empty($value)) { | |
8ce32af6 | 36 | return; |
443cecd2 NL |
37 | } |
38 | $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); | |
8ce32af6 | 39 | |
443cecd2 | 40 | return $filterQuery->createCondition($expression); |
8ce32af6 | 41 | }, |
443cecd2 | 42 | )); |
26864574 NL |
43 | } |
44 | ||
45 | public function getName() | |
46 | { | |
47 | return 'entry_filter'; | |
48 | } | |
49 | ||
50 | public function configureOptions(OptionsResolver $resolver) | |
51 | { | |
52 | $resolver->setDefaults(array( | |
8ce32af6 JB |
53 | 'csrf_protection' => false, |
54 | 'validation_groups' => array('filtering'), | |
26864574 NL |
55 | )); |
56 | } | |
57 | } |