src/Form/RegisterSpeakerFieldsType.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Speaker;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\FileType;
  6. use Symfony\Component\Form\FormBuilderInterface;
  7. use App\Entity\Category;
  8. use App\Form\MultipleCheckboxType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  10. use Symfony\Component\Validator\Constraints\Count;
  11. use Symfony\Component\Validator\Constraints\File;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\OptionsResolver\OptionsResolver;
  14. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  15. class RegisterSpeakerFieldsType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options)
  18.     {
  19.         $builder
  20.             ->add('photo'FileType::class, [
  21.                 'label' => 'label.avatar',
  22.                 'mapped'      => false,
  23.                 'required'    => true,
  24.                 'constraints' => [
  25.                     new File(
  26.                         [
  27.                             'maxSize' => '50m',
  28.                             'mimeTypes' => [
  29.                                 'image/*',
  30.                             ],
  31.                         ]
  32.                     ),
  33.                 ],
  34.             ])
  35.             ->add('shortDescription'TextareaType::class, [
  36.                 'label' => 'label.short_description',
  37.                 'attr'     => [
  38.                     'class' => 'textarea dots',
  39.                 ],
  40.                 'required' => true,
  41.                 'constraints' => [
  42.                     new Length(['max' => 300'maxMessage' => 'Описание должно быть не длиннее {{ limit }} символов'])
  43.                 ],
  44.             ])
  45.             ->add('categories'EntityType::class, [
  46.                 'class' => Category::class,
  47.                 'label' => 'label.categories',
  48.                 'multiple' => true,
  49.                 'constraints' => [
  50.                     new Count([
  51.                         'min' => 0,
  52.                         'max' => 3
  53.                     ]),
  54.                 ]
  55.             ])
  56.         ;
  57.     }
  58.     public function configureOptions(OptionsResolver $resolver): void
  59.     {
  60.         $resolver->setDefaults([
  61.             'data_class' => Speaker::class,
  62.         ]);
  63.     }
  64. }