]>
Commit | Line | Data |
---|---|---|
4d85d7e9 | 1 | <?php |
4346a860 | 2 | |
4d85d7e9 J |
3 | namespace Wallabag\CoreBundle\Form\Type; |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
619cc453 | 6 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
bca54859 | 7 | use Symfony\Component\Form\Extension\Core\Type\RangeType; |
619cc453 | 8 | use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
4d85d7e9 | 9 | use Symfony\Component\Form\FormBuilderInterface; |
75e9d1df | 10 | use Symfony\Component\OptionsResolver\OptionsResolver; |
4d85d7e9 J |
11 | |
12 | class ConfigType extends AbstractType | |
13 | { | |
32da2a70 | 14 | private $themes = array(); |
c89d35e8 | 15 | private $languages = array(); |
32da2a70 J |
16 | |
17 | /** | |
c89d35e8 NL |
18 | * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes) |
19 | * @param array $languages Languages come from configuration, array just code language as key and label as value | |
32da2a70 | 20 | */ |
c89d35e8 | 21 | public function __construct($themes, $languages) |
32da2a70 J |
22 | { |
23 | $this->themes = array_combine( | |
24 | $themes, | |
25 | array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes) | |
26 | ); | |
c89d35e8 NL |
27 | |
28 | $this->languages = $languages; | |
32da2a70 J |
29 | } |
30 | ||
4d85d7e9 J |
31 | public function buildForm(FormBuilderInterface $builder, array $options) |
32 | { | |
33 | $builder | |
619cc453 | 34 | ->add('theme', ChoiceType::class, array( |
75e9d1df JB |
35 | 'choices' => array_flip($this->themes), |
36 | 'choices_as_values' => true, | |
37 | )) | |
371ac69a | 38 | ->add('items_per_page') |
bca54859 NL |
39 | ->add('reading_speed', RangeType::class, array( |
40 | 'attr' => array( | |
41 | 'min' => 0.5, | |
42 | 'max' => 2, | |
43 | 'step' => 0.5, | |
44 | ), | |
45 | )) | |
619cc453 | 46 | ->add('language', ChoiceType::class, array( |
5c895a7f JB |
47 | 'choices' => array_flip($this->languages), |
48 | 'choices_as_values' => true, | |
c89d35e8 | 49 | )) |
619cc453 | 50 | ->add('save', SubmitType::class) |
4d85d7e9 J |
51 | ; |
52 | } | |
53 | ||
75e9d1df | 54 | public function configureOptions(OptionsResolver $resolver) |
4d85d7e9 J |
55 | { |
56 | $resolver->setDefaults(array( | |
57 | 'data_class' => 'Wallabag\CoreBundle\Entity\Config', | |
58 | )); | |
59 | } | |
60 | ||
619cc453 | 61 | public function getBlockPrefix() |
4d85d7e9 J |
62 | { |
63 | return 'config'; | |
64 | } | |
65 | } |