sf-api-example/src/AppBundle/Form/CategoryType.php

52 lines
1.2 KiB
PHP

<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use AppBundle\Entity\Category;
class CategoryType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'name',
TextType::class,
[
'label' => 'Nom',
'required' => false, // html5 validation disable for the example
'constraints' => [
new NotBlank(),
],
]
);
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Category::class,
'csrf_protection' => false,
'allow_extra_fields' => true,
]);
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return '';
}
}