]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Added setting to have a personal reading time
[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\RangeType;
8 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
9 use Symfony\Component\Form\FormBuilderInterface;
10 use Symfony\Component\OptionsResolver\OptionsResolver;
11
12 class ConfigType extends AbstractType
13 {
14 private $themes = array();
15 private $languages = array();
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) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes)
26 );
27
28 $this->languages = $languages;
29 }
30
31 public function buildForm(FormBuilderInterface $builder, array $options)
32 {
33 $builder
34 ->add('theme', ChoiceType::class, array(
35 'choices' => array_flip($this->themes),
36 'choices_as_values' => true,
37 ))
38 ->add('items_per_page')
39 ->add('reading_speed', RangeType::class, array(
40 'attr' => array(
41 'min' => 0.5,
42 'max' => 2,
43 'step' => 0.5,
44 ),
45 ))
46 ->add('language', ChoiceType::class, array(
47 'choices' => array_flip($this->languages),
48 'choices_as_values' => true,
49 ))
50 ->add('save', SubmitType::class)
51 ;
52 }
53
54 public function configureOptions(OptionsResolver $resolver)
55 {
56 $resolver->setDefaults(array(
57 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
58 ));
59 }
60
61 public function getBlockPrefix()
62 {
63 return 'config';
64 }
65 }