]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ConfigType.php
Merge pull request #1446 from wallabag/v2-language-config
[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\FormBuilderInterface;
7 use Symfony\Component\OptionsResolver\OptionsResolver;
8
9 class ConfigType extends AbstractType
10 {
11 private $themes = array();
12 private $languages = array();
13
14 /**
15 * @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
16 * @param array $languages Languages come from configuration, array just code language as key and label as value
17 */
18 public function __construct($themes, $languages)
19 {
20 $this->themes = array_combine(
21 $themes,
22 array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes)
23 );
24
25 $this->languages = $languages;
26 }
27
28 public function buildForm(FormBuilderInterface $builder, array $options)
29 {
30 $builder
31 ->add('theme', 'choice', array(
32 'choices' => array_flip($this->themes),
33 'choices_as_values' => true,
34 ))
35 ->add('items_per_page')
36 ->add('language', 'choice', array(
37 'choices' => $this->languages,
38 ))
39 ->add('save', 'submit')
40 ;
41 }
42
43 public function configureOptions(OptionsResolver $resolver)
44 {
45 $resolver->setDefaults(array(
46 'data_class' => 'Wallabag\CoreBundle\Entity\Config',
47 ));
48 }
49
50 public function getName()
51 {
52 return 'config';
53 }
54 }