3 namespace Wallabag\CoreBundle\Form\Type
;
5 use Doctrine\ORM\EntityRepository
;
6 use Lexik\Bundle\FormFilterBundle\Filter\Query\QueryInterface
;
7 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\NumberRangeFilterType
;
8 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\DateRangeFilterType
;
9 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\TextFilterType
;
10 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\CheckboxFilterType
;
11 use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType
;
12 use Symfony\Component\Form\AbstractType
;
13 use Symfony\Component\Form\FormBuilderInterface
;
14 use Symfony\Component\OptionsResolver\OptionsResolver
;
15 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage
;
17 class EntryFilterType
extends AbstractType
23 * Repository & user are used to get a list of language entries for this user.
25 * @param EntityRepository $entryRepository
26 * @param TokenStorage $token
28 public function __construct(EntityRepository
$entryRepository, TokenStorage
$token)
30 $this->repository
= $entryRepository;
31 $this->user
= $token->getToken()->getUser();
34 public function buildForm(FormBuilderInterface
$builder, array $options)
37 ->add('readingTime', NumberRangeFilterType
::class, [
38 'label' => 'entry.filters.reading_time.label',
40 ->add('createdAt', DateRangeFilterType
::class, [
41 'left_date_options' => [
43 'placeholder' => 'dd/mm/yyyy',
45 'format' => 'dd/MM/yyyy',
46 'widget' => 'single_text',
48 'right_date_options' => [
50 'placeholder' => 'dd/mm/yyyy',
52 'format' => 'dd/MM/yyyy',
53 'widget' => 'single_text',
55 'label' => 'entry.filters.created_at.label',
58 ->add('domainName', TextFilterType
::class, [
59 'apply_filter' => function (QueryInterface
$filterQuery, $field, $values) {
60 $value = $values['value'];
61 if (strlen($value) <= 2 || empty($value)) {
64 $expression = $filterQuery->getExpr()->like($field, $filterQuery->getExpr()->literal('%'.$value.'%'));
66 return $filterQuery->createCondition($expression);
68 'label' => 'entry.filters.domain_label',
70 ->add('isArchived', CheckboxFilterType
::class, [
71 'label' => 'entry.filters.archived_label',
73 ->add('isStarred', CheckboxFilterType
::class, [
74 'label' => 'entry.filters.starred_label',
76 ->add('previewPicture', CheckboxFilterType
::class, [
77 'apply_filter' => function (QueryInterface
$filterQuery, $field, $values) {
78 if (false === $values['value']) {
82 $expression = $filterQuery->getExpr()->isNotNull($field);
84 return $filterQuery->createCondition($expression);
86 'label' => 'entry.filters.preview_picture_label',
88 ->add('language', ChoiceFilterType
::class, [
89 'choices' => array_flip($this->repository
->findDistinctLanguageByUser($this->user
->getId())),
90 'choices_as_values' => true,
91 'label' => 'entry.filters.language_label',
96 public function getBlockPrefix()
98 return 'entry_filter';
101 public function configureOptions(OptionsResolver
$resolver)
103 $resolver->setDefaults([
104 'csrf_protection' => false,
105 'validation_groups' => ['filtering'],