]>
Commit | Line | Data |
---|---|---|
19c407f2 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\Form\Type; | |
4 | ||
19c407f2 NL |
5 | use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\ChoiceFilterType; |
6 | use Symfony\Component\Form\AbstractType; | |
7 | use Symfony\Component\Form\FormBuilderInterface; | |
8 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
9 | use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | |
10 | ||
11 | class EntrySortType extends AbstractType | |
12 | { | |
13 | private $user; | |
14 | ||
15 | public function __construct(TokenStorageInterface $tokenStorage) | |
16 | { | |
17 | $this->user = $tokenStorage->getToken() ? $tokenStorage->getToken()->getUser() : null; | |
18 | ||
19 | if (null === $this->user || !\is_object($this->user)) { | |
20 | return; | |
21 | } | |
22 | } | |
23 | ||
24 | public function buildForm(FormBuilderInterface $builder, array $options) | |
25 | { | |
26 | $builder | |
9b555229 NL |
27 | ->add('sortOrder', ChoiceFilterType::class, [ |
28 | 'choices' => [ | |
29 | 'entry.sort.ascending' => 'asc', | |
30 | 'entry.sort.descending' => 'desc', | |
31 | ], | |
32 | 'label' => 'entry.sort.order_label', | |
33 | ]) | |
19c407f2 NL |
34 | ->add('sortType', ChoiceFilterType::class, [ |
35 | 'choices' => [ | |
9b555229 NL |
36 | 'entry.sort.by.creation_date' => 'createdAt', |
37 | 'entry.sort.by.starred_date' => 'starredAt', | |
38 | 'entry.sort.by.archive_date' => 'archivedAt', | |
39 | 'entry.sort.by.title' => 'title', | |
40 | 'entry.sort.by.last_updated' => 'updatedAt', | |
19c407f2 NL |
41 | ], |
42 | 'label' => 'entry.sort.status_label', | |
43 | ]) | |
44 | ; | |
45 | } | |
46 | ||
47 | public function getBlockPrefix() | |
48 | { | |
49 | return 'entry_sort'; | |
50 | } | |
51 | ||
52 | public function configureOptions(OptionsResolver $resolver) | |
53 | { | |
54 | $resolver->setDefaults([ | |
55 | 'csrf_protection' => false, | |
56 | 'validation_groups' => ['sortering'], | |
57 | ]); | |
58 | } | |
59 | } |