<?php
namespace App\Form;
use App\Entity\Speaker;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\FormBuilderInterface;
use App\Entity\Category;
use App\Form\MultipleCheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Validator\Constraints\Count;
use Symfony\Component\Validator\Constraints\File;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
class RegisterSpeakerFieldsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('photo', FileType::class, [
'label' => 'label.avatar',
'mapped' => false,
'required' => true,
'constraints' => [
new File(
[
'maxSize' => '50m',
'mimeTypes' => [
'image/*',
],
]
),
],
])
->add('shortDescription', TextareaType::class, [
'label' => 'label.short_description',
'attr' => [
'class' => 'textarea dots',
],
'required' => true,
'constraints' => [
new Length(['max' => 300, 'maxMessage' => 'Описание должно быть не длиннее {{ limit }} символов'])
],
])
->add('categories', EntityType::class, [
'class' => Category::class,
'label' => 'label.categories',
'multiple' => true,
'constraints' => [
new Count([
'min' => 0,
'max' => 3
]),
]
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Speaker::class,
]);
}
}