2015-03-03 20:38:52 +00:00
|
|
|
<?php
|
|
|
|
|
2019-01-20 01:52:57 +00:00
|
|
|
namespace App\Form;
|
2015-03-03 20:38:52 +00:00
|
|
|
|
2019-01-20 04:11:30 +00:00
|
|
|
use App\Entity\{Paste, Language};
|
2016-12-18 23:18:28 +00:00
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
2015-03-03 20:38:52 +00:00
|
|
|
use Symfony\Component\Form\AbstractType;
|
2019-01-20 04:11:30 +00:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\{CheckboxType, ChoiceType, TextareaType, TextType};
|
2015-03-03 20:38:52 +00:00
|
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
2016-12-18 23:18:28 +00:00
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
2015-03-03 20:38:52 +00:00
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
use Doctrine\ORM\QueryBuilder;
|
|
|
|
|
2019-01-20 04:11:30 +00:00
|
|
|
class PasteType extends AbstractType
|
2015-03-03 20:38:52 +00:00
|
|
|
{
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
|
|
{
|
|
|
|
$builder
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('text', TextareaType::class, ['label' => 'paste_add_form_text'])
|
|
|
|
->add('description', TextareaType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_description',
|
|
|
|
'required' => false,
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('fileName', TextType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_file_name',
|
|
|
|
'required' => false,
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('author', TextType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_author',
|
|
|
|
'required' => false,
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('expire', ChoiceType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_expire',
|
|
|
|
'mapped' => false,
|
|
|
|
// @todo move to config
|
|
|
|
'choices' => [
|
2016-12-18 23:18:28 +00:00
|
|
|
'5 minutes'=> 300,
|
|
|
|
'1 hour' => 3600,
|
|
|
|
'3 hours' => 10800,
|
|
|
|
'12 hours' => 43200,
|
|
|
|
'1 day' => 86400,
|
|
|
|
'1 week' => 604800,
|
|
|
|
'1 month' => 2419200,
|
|
|
|
'3 months' => 7257600,
|
|
|
|
'6 months' => 14515200,
|
|
|
|
'1 year' => 29030400,
|
|
|
|
'Never' => 0,
|
2015-03-03 20:38:52 +00:00
|
|
|
]
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('private', CheckboxType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_private',
|
|
|
|
'required' => false,
|
|
|
|
'mapped' => false
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('language', EntityType::class, [
|
2015-03-03 20:38:52 +00:00
|
|
|
'label' => 'paste_add_form_language',
|
2019-01-20 01:52:57 +00:00
|
|
|
'class' => Language::class,
|
2015-03-03 20:38:52 +00:00
|
|
|
'query_builder' => function (EntityRepository $repo) {
|
|
|
|
/* @var $qb QueryBuilder */
|
|
|
|
return $repo->createQueryBuilder('lang')
|
|
|
|
->where('lang.isEnabled = :enabled')
|
|
|
|
->addOrderBy('lang.isPreferred', 'DESC')
|
|
|
|
->addOrderBy('lang.code')
|
|
|
|
->setParameter('enabled', true);
|
|
|
|
},
|
|
|
|
//'preferred_choices' => []
|
|
|
|
])
|
2016-12-18 23:18:28 +00:00
|
|
|
->add('captcha', FakeCaptchaType::class, [
|
2015-10-14 03:53:54 +00:00
|
|
|
'mapped' => false,
|
|
|
|
'required' => true,
|
|
|
|
])
|
2015-03-03 20:38:52 +00:00
|
|
|
;
|
|
|
|
}
|
2016-12-18 23:18:28 +00:00
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
2015-03-03 20:38:52 +00:00
|
|
|
{
|
|
|
|
$resolver->setDefaults([
|
2019-01-20 04:11:30 +00:00
|
|
|
'data_class' => Paste::class
|
2015-03-03 20:38:52 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|