2015-02-16 20:28:49 +00:00
|
|
|
<?php
|
2015-05-30 11:52:26 +00:00
|
|
|
|
2015-02-16 20:28:49 +00:00
|
|
|
namespace Wallabag\CoreBundle\Form\Type;
|
|
|
|
|
|
|
|
use Symfony\Component\Form\AbstractType;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
2015-02-16 20:28:49 +00:00
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2015-06-02 14:58:19 +00:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2015-02-16 20:28:49 +00:00
|
|
|
|
|
|
|
class ConfigType extends AbstractType
|
|
|
|
{
|
2015-02-23 21:55:06 +00:00
|
|
|
private $themes = array();
|
2015-10-01 14:28:38 +00:00
|
|
|
private $languages = array();
|
2015-02-23 21:55:06 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-01 14:28:38 +00:00
|
|
|
* @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
|
|
|
|
* @param array $languages Languages come from configuration, array just code language as key and label as value
|
2015-02-23 21:55:06 +00:00
|
|
|
*/
|
2015-10-01 14:28:38 +00:00
|
|
|
public function __construct($themes, $languages)
|
2015-02-23 21:55:06 +00:00
|
|
|
{
|
|
|
|
$this->themes = array_combine(
|
|
|
|
$themes,
|
|
|
|
array_map(function ($s) { return ucwords(strtolower(str_replace('-', ' ', $s))); }, $themes)
|
|
|
|
);
|
2015-10-01 14:28:38 +00:00
|
|
|
|
|
|
|
$this->languages = $languages;
|
2015-02-23 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 20:28:49 +00:00
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
$builder
|
2015-12-22 09:16:34 +00:00
|
|
|
->add('theme', ChoiceType::class, array(
|
2015-06-02 14:58:19 +00:00
|
|
|
'choices' => array_flip($this->themes),
|
|
|
|
'choices_as_values' => true,
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form_settings.theme_label',
|
|
|
|
))
|
|
|
|
->add('items_per_page', null, array(
|
|
|
|
'label' => 'config.form_settings.items_per_page_label',
|
2015-06-02 14:58:19 +00:00
|
|
|
))
|
2016-03-14 12:49:47 +00:00
|
|
|
->add('reading_speed', ChoiceType::class, array(
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form_settings.reading_speed',
|
2016-03-14 12:49:47 +00:00
|
|
|
'choices' => array(
|
|
|
|
'I read ~100 words per minute' => '0.5',
|
|
|
|
'I read ~200 words per minute' => '1',
|
|
|
|
'I read ~300 words per minute' => '1.5',
|
|
|
|
'I read ~400 words per minute' => '2',
|
2016-03-08 15:44:25 +00:00
|
|
|
),
|
|
|
|
))
|
2015-12-22 09:16:34 +00:00
|
|
|
->add('language', ChoiceType::class, array(
|
2015-12-22 12:00:37 +00:00
|
|
|
'choices' => array_flip($this->languages),
|
|
|
|
'choices_as_values' => true,
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form_settings.language_label',
|
|
|
|
))
|
|
|
|
->add('save', SubmitType::class, array(
|
|
|
|
'label' => 'config.form.save',
|
2015-10-01 14:28:38 +00:00
|
|
|
))
|
2015-02-16 20:28:49 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2015-06-02 14:58:19 +00:00
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
2015-02-16 20:28:49 +00:00
|
|
|
{
|
|
|
|
$resolver->setDefaults(array(
|
|
|
|
'data_class' => 'Wallabag\CoreBundle\Entity\Config',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2015-12-22 09:16:34 +00:00
|
|
|
public function getBlockPrefix()
|
2015-02-16 20:28:49 +00:00
|
|
|
{
|
|
|
|
return 'config';
|
|
|
|
}
|
|
|
|
}
|