]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | ||
3 | namespace Wallabag\CoreBundle\Form\Type; | |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
6 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |
7 | use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |
8 | use Symfony\Component\Form\FormBuilderInterface; | |
9 | use Symfony\Component\OptionsResolver\OptionsResolver; | |
10 | ||
11 | class ConfigType extends AbstractType | |
12 | { | |
13 | private $themes = []; | |
14 | private $languages = []; | |
15 | ||
16 | /** | |
17 | * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes) | |
18 | * @param array $languages Languages come from configuration, array just code language as key and label as value | |
19 | */ | |
20 | public function __construct($themes, $languages) | |
21 | { | |
22 | $this->themes = array_combine( | |
23 | $themes, | |
24 | array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes) | |
25 | ); | |
26 | ||
27 | $this->languages = $languages; | |
28 | } | |
29 | ||
30 | public function buildForm(FormBuilderInterface $builder, array $options) | |
31 | { | |
32 | $builder | |
33 | ->add('theme', ChoiceType::class, [ | |
34 | 'choices' => array_flip($this->themes), | |
35 | 'choices_as_values' => true, | |
36 | 'label' => 'config.form_settings.theme_label', | |
37 | ]) | |
38 | ->add('items_per_page', null, [ | |
39 | 'label' => 'config.form_settings.items_per_page_label', | |
40 | ]) | |
41 | ->add('reading_speed', ChoiceType::class, [ | |
42 | 'label' => 'config.form_settings.reading_speed.label', | |
43 | 'choices' => [ | |
44 | 'config.form_settings.reading_speed.100_word' => '0.5', | |
45 | 'config.form_settings.reading_speed.200_word' => '1', | |
46 | 'config.form_settings.reading_speed.300_word' => '1.5', | |
47 | 'config.form_settings.reading_speed.400_word' => '2', | |
48 | ], | |
49 | ]) | |
50 | ->add('language', ChoiceType::class, [ | |
51 | 'choices' => array_flip($this->languages), | |
52 | 'choices_as_values' => true, | |
53 | 'label' => 'config.form_settings.language_label', | |
54 | ]) | |
55 | ->add('save', SubmitType::class, [ | |
56 | 'label' => 'config.form.save', | |
57 | ]) | |
58 | ; | |
59 | } | |
60 | ||
61 | public function configureOptions(OptionsResolver $resolver) | |
62 | { | |
63 | $resolver->setDefaults([ | |
64 | 'data_class' => 'Wallabag\CoreBundle\Entity\Config', | |
65 | ]); | |
66 | } | |
67 | ||
68 | public function getBlockPrefix() | |
69 | { | |
70 | return 'config'; | |
71 | } | |
72 | } |