src/Form/DonationsFormType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use Symfony\Component\Form\AbstractType;
  4. use Symfony\Component\Form\FormBuilderInterface;
  5. use Symfony\Component\OptionsResolver\OptionsResolver;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use Symfony\Component\Form\Extension\Core\Type\TextType;
  9. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  10. use App\Entity\Donations;
  11. #use Symfony\Component\Form\FormEvent;
  12. #use Symfony\Component\Form\FormEvents;
  13. Class DonationsFormType extends AbstractType
  14. {
  15.     public function buildForm(FormBuilderInterface $builder, array $options)
  16.     {
  17.         $builder
  18.             ->add('userid'HiddenType::Class)
  19.             ->add('amount'TextType::Class, [
  20.                 'constraints' => [
  21.                     new Assert\NotBlank(),
  22.                     new Assert\Length(['min' => 1'max' => 5]),
  23.                 ],
  24.                 'data' => isset($options['data']) ? $options['data']->getAmount() : '5'
  25.             ])
  26.         ;
  27.         /*$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  28.             $donation = $event->getData();
  29.             $form = $event->getForm();
  30.             if (!$donation || null === $donation->getId()) {
  31.                 $form->add('sidebar', HiddenType::Class, [
  32.                     'data' => '1',
  33.                     'required' => true
  34.                 ]);
  35.             }
  36.         });*/
  37.     }
  38.     public function configureOptions(OptionsResolver $resolver)
  39.     {
  40.         $resolver->setDefaults([
  41.             'data_class' => Donations::Class
  42.         ]);
  43.     }
  44. }