]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Replace slider with select
[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
11 class ConfigType extends AbstractType
12 {
13 private $themes = array();
14 private $languages = array();
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, array(
34 'choices' => array_flip($this->themes),
35 'choices_as_values' => true,
36 ))
37 ->add('items_per_page')
38 ->add('reading_speed', ChoiceType::class, array(
39 'choices' => array(
40 'I read ~100 words per minute' => '0.5',
41 'I read ~200 words per minute' => '1',
42 'I read ~300 words per minute' => '1.5',
43 'I read ~400 words per minute' => '2',
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 }