]> git.immae.eu Git - github/wallabag/wallabag.git/blame - 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
CommitLineData
4d85d7e9 1<?php
4346a860 2
4d85d7e9
J
3namespace Wallabag\CoreBundle\Form\Type;
4
5use Symfony\Component\Form\AbstractType;
619cc453 6use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
41022cb2 7use Symfony\Component\Form\Extension\Core\Type\IntegerType;
619cc453 8use Symfony\Component\Form\Extension\Core\Type\SubmitType;
4d85d7e9 9use Symfony\Component\Form\FormBuilderInterface;
75e9d1df 10use Symfony\Component\OptionsResolver\OptionsResolver;
f052f1fd 11use Wallabag\CoreBundle\Entity\Config;
4d85d7e9
J
12
13class ConfigType extends AbstractType
14{
4094ea47
JB
15 private $themes = [];
16 private $languages = [];
32da2a70
J
17
18 /**
c89d35e8
NL
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
32da2a70 21 */
c89d35e8 22 public function __construct($themes, $languages)
32da2a70
J
23 {
24 $this->themes = array_combine(
25 $themes,
0cecfa25
JB
26 array_map(function ($s) {
27 return ucwords(strtolower(str_replace('-', ' ', $s)));
28 }, $themes)
32da2a70 29 );
c89d35e8
NL
30
31 $this->languages = $languages;
32da2a70
J
32 }
33
4d85d7e9
J
34 public function buildForm(FormBuilderInterface $builder, array $options)
35 {
36 $builder
4094ea47 37 ->add('theme', ChoiceType::class, [
75e9d1df 38 'choices' => array_flip($this->themes),
0d42217e 39 'label' => 'config.form_settings.theme_label',
4094ea47 40 ])
41022cb2 41 ->add('items_per_page', IntegerType::class, [
0d42217e 42 'label' => 'config.form_settings.items_per_page_label',
ab9eb5cd 43 'property_path' => 'itemsPerPage',
4094ea47 44 ])
41022cb2 45 ->add('reading_speed', IntegerType::class, [
f3e49264 46 'label' => 'config.form_settings.reading_speed.label',
ab9eb5cd 47 'property_path' => 'readingSpeed',
4094ea47 48 ])
a42f38d9
NL
49 ->add('action_mark_as_read', ChoiceType::class, [
50 'label' => 'config.form_settings.action_mark_as_read.label',
ab9eb5cd 51 'property_path' => 'actionMarkAsRead',
a42f38d9 52 'choices' => [
f052f1fd
NL
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,
a42f38d9
NL
55 ],
56 ])
4094ea47 57 ->add('language', ChoiceType::class, [
5c895a7f 58 'choices' => array_flip($this->languages),
0d42217e 59 'label' => 'config.form_settings.language_label',
4094ea47 60 ])
ebe0787e 61 ->add('pocket_consumer_key', null, [
ab9eb5cd 62 'property_path' => 'pocketConsumerKey',
ebe0787e
JB
63 'label' => 'config.form_settings.pocket_consumer_key_label',
64 ])
4094ea47 65 ->add('save', SubmitType::class, [
0d42217e 66 'label' => 'config.form.save',
4094ea47 67 ])
4d85d7e9
J
68 ;
69 }
70
75e9d1df 71 public function configureOptions(OptionsResolver $resolver)
4d85d7e9 72 {
4094ea47 73 $resolver->setDefaults([
4d85d7e9 74 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
4094ea47 75 ]);
4d85d7e9
J
76 }
77
619cc453 78 public function getBlockPrefix()
4d85d7e9
J
79 {
80 return 'config';
81 }
82}