src/Form/UserValidateType.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Form;
  4. use App\Entity\Local\PushNotificationSubscription;
  5. use App\Entity\Vista\LoyaltyMember;
  6. use App\Form\DataTransformer\VistaTimestampToDateTimeTransformer;
  7. use Symfony\Component\Form\AbstractType;
  8. use Symfony\Component\Form\Extension\Core\DataTransformer\DateTimeImmutableToDateTimeTransformer;
  9. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  10. use Symfony\Component\Form\Extension\Core\Type\FormType;
  11. use Symfony\Component\Form\FormBuilderInterface;
  12. use Symfony\Component\Form\FormEvent;
  13. use Symfony\Component\Form\FormEvents;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. class UserValidateType extends AbstractType
  16. {
  17.     public function buildForm(FormBuilderInterface $builder, array $options)
  18.     {
  19.         $builder
  20.             ->add('MemberId')
  21.             ->add('FirstName')
  22.             ->add('LastName')
  23.             ->add('Email')
  24.             ->add('UserName')
  25.             ->add('Password')
  26.             ->add('FullName')
  27.             ->add('CardNumber')
  28.             ->add('MobilePhone')
  29.             ->add('ClubID')
  30.             ->add('MiddleName')
  31.             ->add('Address1')
  32.             ->add('State')
  33.             ->add('City')
  34.             ->add('ZipCode')
  35.             ->add('EducationLevel')
  36.             ->add('HouseholdIncome')
  37.             ->add('PersonsInHousehold')
  38.             ->add('DateOfBirth')
  39.             ->add('Status')
  40.             ->add('Suburb')
  41.             ->add('Gender')
  42.             ->add('ContactByThirdParty')
  43.             ->add('SendNewsletter')
  44.             ->add('Opera')
  45.             ->add('FamilyClubAndChildrenActions')
  46.             ->add('RemembranceEventsService')
  47.             ->add('WishToReceiveSMS')
  48.             ->add('WorkZipCode')
  49.             ->add('CardList'CollectionType::class, ['allow_add' => true])
  50.             ->add('PreferredGenres'CollectionType::class, ['allow_add' => true])
  51.             ->add('PreferenceList'CollectionType::class, ['allow_add' => true])
  52.             ->add('Occupation')
  53.             ->add('MaritalStatus')
  54.             ->add('MailingFrequency')
  55.             ->add('Pin')
  56.             ->add('MemberLevelId')
  57.             ->add('MemberLevelName')
  58.             ->add('LoyaltySessionExpiry')
  59.             ->add('LoyaltySessionToken')
  60.             ->add('GiftCard')
  61.             ->add('GiftCardBalance')
  62.             ->add('IsBannedFromMakingUnpaidBookingsUntil')
  63.             ->add('MembershipActivated')
  64.             ->add('MemberItemId')
  65.             ->add('ExternalID')
  66.             ->add('NationalID')
  67.             ->add('IsAnonymous')
  68.             ->add('MemberLanguageIETFCode')
  69.             ->add('UserSessionId')
  70.             ->add('ExpiryDate')
  71.             ->add('BalanceList'CollectionType::class, ['allow_add' => true'entry_type' => MemberBalanceType::class])
  72.             ->add('ExpiryPointsList'CollectionType::class, ['allow_add' => true'allow_delete' => true'entry_type' => ExpiryPointType::class])
  73.             ->add('PreferredComplexList'CollectionType::class, ['allow_add' => true'allow_delete' => true])
  74.             ->add(
  75.                 'PushNotificationSubscription',
  76.                 FormType::class,
  77.                 ['data_class' => PushNotificationSubscription::class]
  78.             )
  79.             ;
  80.         $builder->get('DateOfBirth')
  81.             ->addModelTransformer(new VistaTimestampToDateTimeTransformer())
  82.             ->addModelTransformer(new DateTimeImmutableToDateTimeTransformer())
  83.         ;
  84.         $builder->get('LoyaltySessionExpiry')
  85.             ->addModelTransformer(new VistaTimestampToDateTimeTransformer())
  86.         ;
  87.         $builder->get('ExpiryDate')
  88.             ->addModelTransformer(new VistaTimestampToDateTimeTransformer())
  89.             ;
  90.         $builder->get('ClubID')->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) {
  91.             if (empty($event->getData())) {
  92.                 $event->setData('1');
  93.             }
  94.         });
  95.         $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
  96.             /** @var LoyaltyMember $user */
  97.             $user $event->getData();
  98.             $user->setPreferenceList([]);
  99.         });
  100.         foreach ($builder->all() as $item) {
  101.             /** @var FormBuilderInterface $item */
  102.             $item->setPropertyPath(lcfirst($item->getName()));
  103.         }
  104.     }
  105.     public function configureOptions(OptionsResolver $resolver)
  106.     {
  107.         $resolver->setDefaults([
  108.             'data_class'      => LoyaltyMember::class,
  109.             'allow_extra_fields' => true,
  110.             'csrf_protection' => false,
  111.         ]);
  112.     }
  113. }