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