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