]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Add ability to manually define the reading speed
[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\IntegerType;
8 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
9 use Symfony\Component\Form\FormBuilderInterface;
10 use Symfony\Component\OptionsResolver\OptionsResolver;
11 use Wallabag\CoreBundle\Entity\Config;
12
13 class ConfigType extends AbstractType
14 {
15 private $themes = [];
16 private $languages = [];
17
18 /**
19 * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
20 * @param array $languages Languages come from configuration, array just code language as key and label as value
21 */
22 public function __construct($themes, $languages)
23 {
24 $this->themes = array_combine(
25 $themes,
26 array_map(function ($s) {
27 return ucwords(strtolower(str_replace('-', ' ', $s)));
28 }, $themes)
29 );
30
31 $this->languages = $languages;
32 }
33
34 public function buildForm(FormBuilderInterface $builder, array $options)
35 {
36 $builder
37 ->add('theme', ChoiceType::class, [
38 'choices' => array_flip($this->themes),
39 'label' => 'config.form_settings.theme_label',
40 ])
41 ->add('items_per_page', IntegerType::class, [
42 'label' => 'config.form_settings.items_per_page_label',
43 'property_path' => 'itemsPerPage',
44 ])
45 ->add('reading_speed', IntegerType::class, [
46 'label' => 'config.form_settings.reading_speed.label',
47 'property_path' => 'readingSpeed',
48 ])
49 ->add('action_mark_as_read', ChoiceType::class, [
50 'label' => 'config.form_settings.action_mark_as_read.label',
51 'property_path' => 'actionMarkAsRead',
52 'choices' => [
53 'config.form_settings.action_mark_as_read.redirect_homepage' => Config::REDIRECT_TO_HOMEPAGE,
54 'config.form_settings.action_mark_as_read.redirect_current_page' => Config::REDIRECT_TO_CURRENT_PAGE,
55 ],
56 ])
57 ->add('language', ChoiceType::class, [
58 'choices' => array_flip($this->languages),
59 'label' => 'config.form_settings.language_label',
60 ])
61 ->add('pocket_consumer_key', null, [
62 'property_path' => 'pocketConsumerKey',
63 'label' => 'config.form_settings.pocket_consumer_key_label',
64 ])
65 ->add('save', SubmitType::class, [
66 'label' => 'config.form.save',
67 ])
68 ;
69 }
70
71 public function configureOptions(OptionsResolver $resolver)
72 {
73 $resolver->setDefaults([
74 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
75 ]);
76 }
77
78 public function getBlockPrefix()
79 {
80 return 'config';
81 }
82 }