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