]>
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 | 29 | 'widget' => 'single_text', |
7d6c3edc JB |
30 | ), |
31 | ) | |
32 | ) | |
443cecd2 | 33 | ->add('domainName', 'filter_text', array( |
8ce32af6 | 34 | 'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { |
443cecd2 NL |
35 | $value = $values['value']; |
36 | if (strlen($value) <= 3 || empty($value)) { | |
8ce32af6 | 37 | return; |
443cecd2 NL |
38 | } |
39 | $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%')); | |
8ce32af6 | 40 | |
443cecd2 | 41 | return $filterQuery->createCondition($expression); |
8ce32af6 | 42 | }, |
89659c9e NL |
43 | )) |
44 | ->add('isArchived', 'filter_checkbox') | |
45 | ->add('isStarred', 'filter_checkbox'); | |
26864574 NL |
46 | } |
47 | ||
48 | public function getName() | |
49 | { | |
50 | return 'entry_filter'; | |
51 | } | |
52 | ||
53 | public function configureOptions(OptionsResolver $resolver) | |
54 | { | |
55 | $resolver->setDefaults(array( | |
8ce32af6 JB |
56 | 'csrf_protection' => false, |
57 | 'validation_groups' => array('filtering'), | |
26864574 NL |
58 | )); |
59 | } | |
60 | } |