Application refactoring according to Symfony's UPGRADE-2.8.md
This commit is contained in:
parent
e716460405
commit
ab8c53da07
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace Skobkin\Bundle\CopyPasteBundle\Controller;
|
namespace Skobkin\Bundle\CopyPasteBundle\Controller;
|
||||||
|
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
@ -75,12 +76,12 @@ class CopypasteController extends Controller
|
||||||
*/
|
*/
|
||||||
private function createCreateForm(Copypaste $entity)
|
private function createCreateForm(Copypaste $entity)
|
||||||
{
|
{
|
||||||
$form = $this->createForm(new CopypasteType(), $entity, [
|
$form = $this->createForm(CopypasteType::class, $entity, [
|
||||||
'action' => $this->generateUrl('copypaste_create'),
|
'action' => $this->generateUrl('copypaste_create'),
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$form->add('submit', 'submit', array('label' => 'Create'));
|
$form->add('submit', SubmitType::class, ['label' => 'Create']);
|
||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,14 @@
|
||||||
|
|
||||||
namespace Skobkin\Bundle\CopyPasteBundle\Form;
|
namespace Skobkin\Bundle\CopyPasteBundle\Form;
|
||||||
|
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
@ -17,43 +23,44 @@ class CopypasteType extends AbstractType
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
->add('text', 'textarea', ['label' => 'paste_add_form_text'])
|
->add('text', TextareaType::class, ['label' => 'paste_add_form_text'])
|
||||||
->add('description', 'textarea', [
|
->add('description', TextareaType::class, [
|
||||||
'label' => 'paste_add_form_description',
|
'label' => 'paste_add_form_description',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('fileName', 'text', [
|
->add('fileName', TextType::class, [
|
||||||
'label' => 'paste_add_form_file_name',
|
'label' => 'paste_add_form_file_name',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('author', 'text', [
|
->add('author', TextType::class, [
|
||||||
'label' => 'paste_add_form_author',
|
'label' => 'paste_add_form_author',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
])
|
])
|
||||||
->add('expire', 'choice', [
|
->add('expire', ChoiceType::class, [
|
||||||
'label' => 'paste_add_form_expire',
|
'label' => 'paste_add_form_expire',
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
|
'choices_as_values' => true,
|
||||||
// @todo move to config
|
// @todo move to config
|
||||||
'choices' => [
|
'choices' => [
|
||||||
300 => '5 minutes',
|
'5 minutes'=> 300,
|
||||||
3600 => '1 hour',
|
'1 hour' => 3600,
|
||||||
10800 => '3 hours',
|
'3 hours' => 10800,
|
||||||
43200 => '12 hours',
|
'12 hours' => 43200,
|
||||||
86400 => '1 day',
|
'1 day' => 86400,
|
||||||
604800 => '1 week',
|
'1 week' => 604800,
|
||||||
2419200 => '1 month',
|
'1 month' => 2419200,
|
||||||
7257600 => '3 months',
|
'3 months' => 7257600,
|
||||||
14515200 => '6 months',
|
'6 months' => 14515200,
|
||||||
29030400 => '1 year',
|
'1 year' => 29030400,
|
||||||
0 => 'Never',
|
'Never' => 0,
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
->add('private', 'checkbox', [
|
->add('private', CheckboxType::class, [
|
||||||
'label' => 'paste_add_form_private',
|
'label' => 'paste_add_form_private',
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'mapped' => false
|
'mapped' => false
|
||||||
])
|
])
|
||||||
->add('language', 'entity', [
|
->add('language', EntityType::class, [
|
||||||
'label' => 'paste_add_form_language',
|
'label' => 'paste_add_form_language',
|
||||||
'class' => 'Skobkin\Bundle\CopyPasteBundle\Entity\Language',
|
'class' => 'Skobkin\Bundle\CopyPasteBundle\Entity\Language',
|
||||||
'query_builder' => function (EntityRepository $repo) {
|
'query_builder' => function (EntityRepository $repo) {
|
||||||
|
@ -66,7 +73,7 @@ class CopypasteType extends AbstractType
|
||||||
},
|
},
|
||||||
//'preferred_choices' => []
|
//'preferred_choices' => []
|
||||||
])
|
])
|
||||||
->add('captcha', 'skobkin_fake_captcha', [
|
->add('captcha', FakeCaptchaType::class, [
|
||||||
'mapped' => false,
|
'mapped' => false,
|
||||||
'required' => true,
|
'required' => true,
|
||||||
])
|
])
|
||||||
|
@ -74,9 +81,9 @@ class CopypasteType extends AbstractType
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param OptionsResolverInterface $resolver
|
* @param OptionsResolver $resolver
|
||||||
*/
|
*/
|
||||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
$resolver->setDefaults([
|
$resolver->setDefaults([
|
||||||
'data_class' => 'Skobkin\Bundle\CopyPasteBundle\Entity\Copypaste'
|
'data_class' => 'Skobkin\Bundle\CopyPasteBundle\Entity\Copypaste'
|
||||||
|
@ -84,10 +91,12 @@ class CopypasteType extends AbstractType
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return null|string
|
||||||
*/
|
*/
|
||||||
public function getName()
|
public function getBlockPrefix()
|
||||||
{
|
{
|
||||||
return 'skobkin_bundle_copypastebundle_copypaste';
|
return 'copypaste';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,4 @@ class FakeCaptchaType extends AbstractType
|
||||||
{
|
{
|
||||||
return 'hidden';
|
return 'hidden';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return 'skobkin_fake_captcha';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1 @@
|
||||||
services:
|
services:
|
||||||
copypaste.form.type.fake_captcha:
|
|
||||||
class: Skobkin\Bundle\CopyPasteBundle\Form\FakeCaptchaType
|
|
||||||
tags:
|
|
||||||
- { name: form.type, alias: skobkin_fake_captcha }
|
|
Loading…
Reference in a new issue