2015-02-16 20:28:49 +00:00
|
|
|
<?php
|
2015-05-30 11:52:26 +00:00
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Wallabag\Form\Type;
|
2015-02-16 20:28:49 +00:00
|
|
|
|
|
|
|
use Symfony\Component\Form\AbstractType;
|
2023-06-13 13:02:48 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
2015-12-22 09:16:34 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
2019-07-08 12:45:45 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
|
2023-07-29 10:26:44 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\RangeType;
|
2015-12-22 09:16:34 +00:00
|
|
|
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;
|
2024-02-19 00:30:12 +00:00
|
|
|
use Wallabag\Entity\Config;
|
2015-02-16 20:28:49 +00:00
|
|
|
|
|
|
|
class ConfigType extends AbstractType
|
|
|
|
{
|
2016-04-12 09:36:01 +00:00
|
|
|
private $languages = [];
|
2023-07-29 10:26:44 +00:00
|
|
|
private $fonts = [];
|
2015-02-23 21:55:06 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-01 14:28:38 +00:00
|
|
|
* @param array $languages Languages come from configuration, array just code language as key and label as value
|
2023-07-29 10:26:44 +00:00
|
|
|
* @param array $fonts Fonts come from configuration, array just font name as key / value
|
2015-02-23 21:55:06 +00:00
|
|
|
*/
|
2023-07-29 10:26:44 +00:00
|
|
|
public function __construct($languages, $fonts)
|
2015-02-23 21:55:06 +00:00
|
|
|
{
|
2015-10-01 14:28:38 +00:00
|
|
|
$this->languages = $languages;
|
2023-07-29 10:26:44 +00:00
|
|
|
$this->fonts = $fonts;
|
2015-02-23 21:55:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 20:28:49 +00:00
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
$builder
|
2023-07-29 10:26:44 +00:00
|
|
|
->add('font', ChoiceType::class, [
|
|
|
|
'choices' => $this->initFonts(),
|
|
|
|
'label' => 'config.form_settings.font_label',
|
|
|
|
'property_path' => 'font',
|
|
|
|
])
|
|
|
|
->add('fontsize', RangeType::class, [
|
|
|
|
'attr' => [
|
|
|
|
'min' => 0.6,
|
|
|
|
'max' => 2,
|
|
|
|
'step' => 0.1,
|
|
|
|
],
|
|
|
|
'label' => 'config.form_settings.fontsize_label',
|
|
|
|
'property_path' => 'fontsize',
|
|
|
|
])
|
|
|
|
->add('lineHeight', RangeType::class, [
|
|
|
|
'attr' => [
|
|
|
|
'min' => 0.6,
|
|
|
|
'max' => 2,
|
|
|
|
'step' => 0.1,
|
|
|
|
],
|
|
|
|
'label' => 'config.form_settings.lineheight_label',
|
|
|
|
'property_path' => 'lineHeight',
|
|
|
|
])
|
|
|
|
->add('maxWidth', RangeType::class, [
|
|
|
|
'attr' => [
|
|
|
|
'min' => 20,
|
|
|
|
'max' => 60,
|
|
|
|
'step' => 5,
|
|
|
|
],
|
|
|
|
'label' => 'config.form_settings.maxwidth_label',
|
|
|
|
'property_path' => 'maxWidth',
|
|
|
|
])
|
2019-07-08 12:45:45 +00:00
|
|
|
->add('items_per_page', IntegerType::class, [
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form_settings.items_per_page_label',
|
2017-05-04 22:12:16 +00:00
|
|
|
'property_path' => 'itemsPerPage',
|
2016-04-12 09:36:01 +00:00
|
|
|
])
|
2023-06-13 13:02:48 +00:00
|
|
|
->add('display_thumbnails', CheckboxType::class, [
|
|
|
|
'label' => 'config.form_settings.display_thumbnails_label',
|
|
|
|
'property_path' => 'displayThumbnails',
|
|
|
|
'required' => false,
|
|
|
|
])
|
2019-07-08 12:45:45 +00:00
|
|
|
->add('reading_speed', IntegerType::class, [
|
2016-03-20 21:09:00 +00:00
|
|
|
'label' => 'config.form_settings.reading_speed.label',
|
2017-05-04 22:12:16 +00:00
|
|
|
'property_path' => 'readingSpeed',
|
2016-04-12 09:36:01 +00:00
|
|
|
])
|
2016-11-06 11:02:39 +00:00
|
|
|
->add('action_mark_as_read', ChoiceType::class, [
|
|
|
|
'label' => 'config.form_settings.action_mark_as_read.label',
|
2017-05-04 22:12:16 +00:00
|
|
|
'property_path' => 'actionMarkAsRead',
|
2016-11-06 11:02:39 +00:00
|
|
|
'choices' => [
|
2016-11-07 08:30:37 +00:00
|
|
|
'config.form_settings.action_mark_as_read.redirect_homepage' => Config::REDIRECT_TO_HOMEPAGE,
|
|
|
|
'config.form_settings.action_mark_as_read.redirect_current_page' => Config::REDIRECT_TO_CURRENT_PAGE,
|
2016-11-06 11:02:39 +00:00
|
|
|
],
|
|
|
|
])
|
2016-04-12 09:36:01 +00:00
|
|
|
->add('language', ChoiceType::class, [
|
2015-12-22 12:00:37 +00:00
|
|
|
'choices' => array_flip($this->languages),
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form_settings.language_label',
|
2016-04-12 09:36:01 +00:00
|
|
|
])
|
2016-09-16 20:22:25 +00:00
|
|
|
->add('pocket_consumer_key', null, [
|
2017-05-04 22:12:16 +00:00
|
|
|
'property_path' => 'pocketConsumerKey',
|
2016-09-16 20:22:25 +00:00
|
|
|
'label' => 'config.form_settings.pocket_consumer_key_label',
|
|
|
|
])
|
2016-04-12 09:36:01 +00:00
|
|
|
->add('save', SubmitType::class, [
|
2016-03-09 07:59:08 +00:00
|
|
|
'label' => 'config.form.save',
|
2016-04-12 09:36:01 +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
|
|
|
{
|
2016-04-12 09:36:01 +00:00
|
|
|
$resolver->setDefaults([
|
2022-09-01 18:54:56 +00:00
|
|
|
'data_class' => Config::class,
|
2016-04-12 09:36:01 +00:00
|
|
|
]);
|
2015-02-16 20:28:49 +00:00
|
|
|
}
|
|
|
|
|
2015-12-22 09:16:34 +00:00
|
|
|
public function getBlockPrefix()
|
2015-02-16 20:28:49 +00:00
|
|
|
{
|
|
|
|
return 'config';
|
|
|
|
}
|
2023-07-29 10:26:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an array with font name as key / value.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function initFonts()
|
|
|
|
{
|
|
|
|
$fonts = [];
|
|
|
|
|
|
|
|
foreach ($this->fonts as $font) {
|
|
|
|
$fonts[$font] = $font;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $fonts;
|
|
|
|
}
|
2015-02-16 20:28:49 +00:00
|
|
|
}
|