]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Fixed typo in "first_steps"
[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 = [];
14 private $languages = [];
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) {
25 return ucwords(strtolower(str_replace('-', ' ', $s)));
26 }, $themes)
27 );
28
29 $this->languages = $languages;
30 }
31
32 public function buildForm(FormBuilderInterface $builder, array $options)
33 {
34 $builder
35 ->add('theme', ChoiceType::class, [
36 'choices' => array_flip($this->themes),
37 'label' => 'config.form_settings.theme_label',
38 ])
39 ->add('items_per_page', null, [
40 'label' => 'config.form_settings.items_per_page_label',
41 ])
42 ->add('reading_speed', ChoiceType::class, [
43 'label' => 'config.form_settings.reading_speed.label',
44 'choices' => [
45 'config.form_settings.reading_speed.100_word' => '0.5',
46 'config.form_settings.reading_speed.200_word' => '1',
47 'config.form_settings.reading_speed.300_word' => '1.5',
48 'config.form_settings.reading_speed.400_word' => '2',
49 ],
50 ])
51 ->add('language', ChoiceType::class, [
52 'choices' => array_flip($this->languages),
53 'label' => 'config.form_settings.language_label',
54 ])
55 ->add('pocket_consumer_key', null, [
56 'label' => 'config.form_settings.pocket_consumer_key_label',
57 ])
58 ->add('save', SubmitType::class, [
59 'label' => 'config.form.save',
60 ])
61 ;
62 }
63
64 public function configureOptions(OptionsResolver $resolver)
65 {
66 $resolver->setDefaults([
67 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
68 ]);
69 }
70
71 public function getBlockPrefix()
72 {
73 return 'config';
74 }
75 }