src/Form/UserType.php line 20

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form;
  4. use App\Entity\Vista\LoyaltyMember;
  5. use App\Entity\Local\PushNotificationSubscription;
  6. use App\Repository\CinemaRepository;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  9. use Symfony\Component\Form\Extension\Core\Type\DateType;
  10. use Symfony\Component\Form\Extension\Core\Type\FormType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\FormBuilderInterface;
  13. use Symfony\Component\Form\FormError;
  14. use Symfony\Component\Form\FormEvent;
  15. use Symfony\Component\Form\FormEvents;
  16. use Symfony\Component\OptionsResolver\OptionsResolver;
  17. class UserType extends AbstractType
  18. {
  19.     protected $cinemaRepository;
  20.     public function __construct(CinemaRepository $cinemaRepository)
  21.     {
  22.         $this->cinemaRepository $cinemaRepository;
  23.     }
  24.     public function buildForm(FormBuilderInterface $builder, array $options)
  25.     {
  26.         $builder
  27.             ->add('firstName')
  28.             ->add('lastName')
  29.             ->add('email')
  30.             ->add('userName')
  31.             ->add('password')
  32.             ->add('fullName')
  33.             ->add('cardNumber')
  34.             ->add('mobilePhone'TextType::class, ['empty_data' => ''])
  35.             ->add('clubID')
  36.             ->add('middleName')
  37.             ->add('address1'TextType::class, ['empty_data' => ''])
  38.             ->add('state'TextType::class, ['empty_data' => ''])
  39.             ->add('city'TextType::class, ['empty_data' => ''])
  40.             ->add('zipCode'TextType::class, ['empty_data' => ''])
  41.             ->add('educationLevel')
  42.             ->add('householdIncome')
  43.             ->add('personsInHousehold')
  44.             ->add('dateOfBirth'DateType::class, ['format' => DateType::HTML5_FORMAT'widget' => 'single_text''input' => 'datetime_immutable'])
  45.             ->add('status')
  46.             ->add('suburb')
  47.             ->add('gender')
  48.             ->add('contactByThirdParty')
  49.             ->add('sendNewsletter')
  50.             ->add('opera')
  51.             ->add('familyClubAndChildrenActions')
  52.             ->add('remembranceEventsService')
  53.             ->add('wishToReceiveSMS')
  54.             ->add('workZipCode')
  55.             ->add('cardList'CollectionType::class, ['allow_add' => true])
  56.             ->add('preferredGenres'CollectionType::class, ['allow_add' => true])
  57.             ->add('preferredComplexList'CollectionType::class, ['allow_add' => true'allow_delete' => true])
  58.             ->add('occupation')
  59.             ->add('maritalStatus')
  60.             ->add('mailingFrequency')
  61.             ->add('pin')
  62.             ->add('memberLevelId')
  63.             ->add('memberLevelName')
  64.             ->add('loyaltySessionExpiry')
  65.             ->add('giftCard')
  66.             ->add('giftCardBalance')
  67.             ->add('isBannedFromMakingUnpaidBookingsUntil')
  68.             ->add('membershipActivated')
  69.             ->add('memberItemId')
  70.             ->add('externalID')
  71.             ->add('nationalID')
  72.             ->add('isAnonymous')
  73.             ->add('memberLanguageIETFCode')
  74.             ->add('appleUserId')
  75.             ->add(
  76.                 'pushNotificationSubscription',
  77.                 FormType::class,
  78.                 ['data_class' => PushNotificationSubscription::class]
  79.             )
  80.         ;
  81.         $builder->get('clubID')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
  82.             if (empty($event->getData())) {
  83.                 $event->setData('1');
  84.             }
  85.         });
  86.         $builder->get('preferredComplexList')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
  87.             $data = [];
  88.             foreach ($event->getData() as $cinemaId) {
  89.                 $cinema $this->cinemaRepository->find($cinemaId);
  90.                 if (!$cinema) {
  91.                     $event->getForm()->addError(new FormError('Invalid cinema id %s'$cinemaId));
  92.                     continue;
  93.                 }
  94.                 $data[] = $cinema->getLoyaltyCode();
  95.             }
  96.             $event->setData($data);
  97.         });
  98.     }
  99.     public function configureOptions(OptionsResolver $resolver)
  100.     {
  101.         $resolver->setDefaults([
  102.             'data_class' => LoyaltyMember::class,
  103.             'csrf_protection' => false,
  104.             'allow_extra_fields' => true,
  105.         ]);
  106.     }
  107. }