]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Fix display the form errors correctly
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / ConfigType.php
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 use Wallabag\CoreBundle\Entity\Config;
11
12 class ConfigType extends AbstractType
13 {
14 private $themes = [];
15 private $languages = [];
16
17 /**
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
20 */
21 public function __construct($themes, $languages)
22 {
23 $this->themes = array_combine(
24 $themes,
25 array_map(function ($s) {
26 return ucwords(strtolower(str_replace('-', ' ', $s)));
27 }, $themes)
28 );
29
30 $this->languages = $languages;
31 }
32
33 public function buildForm(FormBuilderInterface $builder, array $options)
34 {
35 $builder
36 ->add('theme', ChoiceType::class, [
37 'choices' => array_flip($this->themes),
38 'label' => 'config.form_settings.theme_label',
39 ])
40 ->add('items_per_page', null, [
41 'label' => 'config.form_settings.items_per_page_label',
42 'property_path' => 'itemsPerPage',
43 ])
44 ->add('reading_speed', ChoiceType::class, [
45 'label' => 'config.form_settings.reading_speed.label',
46 'property_path' => 'readingSpeed',
47 'choices' => [
48 'config.form_settings.reading_speed.100_word' => '0.5',
49 'config.form_settings.reading_speed.200_word' => '1',
50 'config.form_settings.reading_speed.300_word' => '1.5',
51 'config.form_settings.reading_speed.400_word' => '2',
52 ],
53 ])
54 ->add('action_mark_as_read', ChoiceType::class, [
55 'label' => 'config.form_settings.action_mark_as_read.label',
56 'property_path' => 'actionMarkAsRead',
57 'choices' => [
58 'config.form_settings.action_mark_as_read.redirect_homepage' => Config::REDIRECT_TO_HOMEPAGE,
59 'config.form_settings.action_mark_as_read.redirect_current_page' => Config::REDIRECT_TO_CURRENT_PAGE,
60 ],
61 ])
62 ->add('language', ChoiceType::class, [
63 'choices' => array_flip($this->languages),
64 'label' => 'config.form_settings.language_label',
65 ])
66 ->add('pocket_consumer_key', null, [
67 'property_path' => 'pocketConsumerKey',
68 'label' => 'config.form_settings.pocket_consumer_key_label',
69 ])
70 ->add('save', SubmitType::class, [
71 'label' => 'config.form.save',
72 ])
73 ;
74 }
75
76 public function configureOptions(OptionsResolver $resolver)
77 {
78 $resolver->setDefaults([
79 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
80 ]);
81 }
82
83 public function getBlockPrefix()
84 {
85 return 'config';
86 }
87 }