50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Form;
|
|
|
|
use App\Entity\Offer;
|
|
use Symfony\Component\Form\AbstractType;
|
|
use Symfony\Component\Form\Extension\Core\Type\FileType;
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
use Symfony\Component\Form\FormBuilderInterface;
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
use Symfony\Component\Validator\Constraints\Image;
|
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
|
|
|
class OfferFormType extends AbstractType
|
|
{
|
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
|
{
|
|
$builder
|
|
->add('title')
|
|
->add('zipCode', TextType::class, [
|
|
'label' => 'ZIP',
|
|
])
|
|
->add('description', null, [
|
|
'required' => false,
|
|
'constraints' => [
|
|
new NotBlank([
|
|
'message' => 'Please enter a short description',
|
|
]),
|
|
]
|
|
])
|
|
->add('photo', FileType::class, [
|
|
'required' => false,
|
|
'mapped' => false,
|
|
'constraints' => [
|
|
new Image(['maxSize' => '10m'])
|
|
],
|
|
])
|
|
->add('submit', SubmitType::class)
|
|
;
|
|
}
|
|
|
|
public function configureOptions(OptionsResolver $resolver)
|
|
{
|
|
$resolver->setDefaults([
|
|
'data_class' => Offer::class,
|
|
]);
|
|
}
|
|
}
|