src/StartPlatz/Bundle/EventBundle/Form/EventApplicationType.php line 23

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace App\StartPlatz\Bundle\EventBundle\Form;
  3. use App\StartPlatz\Bundle\StartupBundle\Entity\Application;
  4. use App\StartPlatz\Bundle\StartupBundle\Entity\Batch;
  5. use Symfony\Component\Form\AbstractType;
  6. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  7. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  11. use Symfony\Component\Form\Extension\Core\Type\TextType;
  12. use Symfony\Component\Form\Extension\Core\Type\UrlType;
  13. use Symfony\Component\Form\FormBuilderInterface;
  14. use Symfony\Component\OptionsResolver\OptionsResolver;
  15. /**
  16.  * Lightweight form for event registration.
  17.  * Replaces the event-template cases in ApplicationType which pulled in
  18.  * Accelerator/RP fields (industry, teamSize, mvpStatus, etc.) unnecessarily.
  19.  */
  20. class EventApplicationType extends AbstractType
  21. {
  22.     public function buildForm(FormBuilderInterface $builder, array $options): void
  23.     {
  24.         /** @var Batch $batch */
  25.         $batch $options['batch'];
  26.         $settings $options['settings'];
  27.         // Core fields — every event registration needs these
  28.         $builder
  29.             ->add('firstName'TextType::class, ['required' => true'attr' => ['placeholder' => 'first name']])
  30.             ->add('lastName'TextType::class, ['required' => true'attr' => ['placeholder' => 'last name']])
  31.             ->add('email'EmailType::class, ['required' => true'attr' => ['placeholder' => 'email']]);
  32.         // Optional: applicant types (e.g. speed-networking)
  33.         if (isset($settings['applicantTypes']) && $settings['applicantTypes']) {
  34.             $applicantTypes $settings['applicantTypes'];
  35.             $builder->add('applicantType'TextType::class, [
  36.                 'required' => true,
  37.                 'attr' => ['placeholder' => implode(' or '$applicantTypes)],
  38.             ]);
  39.         }
  40.         // Optional: extra fields from batch JSON settings
  41.         if (isset($settings['extraFields'])) {
  42.             foreach ($settings['extraFields'] as $extraField) {
  43.                 $required = ($extraField['required'] ?? '') === 'true' ' *' '';
  44.                 $fieldType = match ($extraField['type'] ?? 'text') {
  45.                     'choice' => ChoiceType::class,
  46.                     'checkbox' => CheckboxType::class,
  47.                     'textarea' => TextareaType::class,
  48.                     default => TextType::class,
  49.                 };
  50.                 $fieldOptions = ['required' => false'mapped' => false];
  51.                 if ($fieldType === ChoiceType::class) {
  52.                     $fieldOptions['choices'] = array_flip($extraField['choices'] ?? []);
  53.                     $fieldOptions['placeholder'] = $extraField['label'] . $required;
  54.                 } else {
  55.                     $fieldOptions['attr'] = ['placeholder' => $extraField['label'] . $required];
  56.                 }
  57.                 $builder->add($extraField['field'], $fieldType$fieldOptions);
  58.             }
  59.         }
  60.         // Conditional batch-driven fields
  61.         if ($batch->getAskForTeam()) {
  62.             $builder->add('startupName'TextType::class, [
  63.                 'required' => false,
  64.                 'attr' => ['placeholder' => 'startupName'],
  65.             ]);
  66.         }
  67.         if ($batch->getHasIncludePhone()) {
  68.             $builder->add('phone'TextType::class, [
  69.                 'required' => false,
  70.                 'attr' => ['placeholder' => 'Phone Number'],
  71.             ]);
  72.         }
  73.         if ($batch->getHasIncludeLinkedIn()) {
  74.             $builder->add('linkedin'UrlType::class, [
  75.                 'required' => false,
  76.                 'default_protocol' => 'https',
  77.                 'attr' => ['placeholder' => 'LinkedIn Url'],
  78.             ]);
  79.         }
  80.         if ($batch->getHasIncludeNewsletterPermission()) {
  81.             $builder->add('hasNewsletterPermissionGiven'CheckboxType::class, ['required' => false]);
  82.         }
  83.         if (isset($settings['hasIncludeVolunteerConsent']) && $settings['hasIncludeVolunteerConsent']) {
  84.             $builder->add('hasVolunteerAgreed'CheckboxType::class, ['required' => false]);
  85.         }
  86.         $builder->add('finish'SubmitType::class, ['label' => 'Apply now']);
  87.     }
  88.     public function configureOptions(OptionsResolver $resolver): void
  89.     {
  90.         $resolver->setDefaults([
  91.             'data_class' => Application::class,
  92.             'settings' => [],
  93.             'program' => null,
  94.             'batch' => null,
  95.         ]);
  96.     }
  97. }